use freeArrayOfString(...); (factorized code)
Allan Cornet [Sat, 1 Dec 2007 17:12:40 +0000 (17:12 +0000)]
30 files changed:
scilab/modules/elementary_functions/sci_gateway/c/sci_gsort.c
scilab/modules/fftw/LibScilab_Import.def
scilab/modules/fftw/sci_gateway/c/sci_fftw_flags.c
scilab/modules/fftw/sci_gateway/c/sci_set_fftw_wisdom.c
scilab/modules/fileio/LibScilab_Import.def
scilab/modules/fileio/sci_gateway/c/sci_fprintfMat.c
scilab/modules/graphics/LibScilab_Import.def
scilab/modules/graphics/sci_gateway/c/sci_xstring.c
scilab/modules/graphics/sci_gateway/c/sci_xstringb.c
scilab/modules/graphics/sci_gateway/c/sci_xstringl.c
scilab/modules/graphics/sci_gateway/c/sci_xtitle.c
scilab/modules/gui/sci_gateway/c/sci_ClipBoard.c
scilab/modules/gui/src/c/LibScilab_Import.def
scilab/modules/history_manager/sci_gateway/c/sci_addhistory.c
scilab/modules/history_manager/src/c/LibScilab_Import.def
scilab/modules/io/sci_gateway/c/sci_host.c
scilab/modules/io/sci_gateway/c/sci_newest.c
scilab/modules/io/src/c/LibScilab_Import.def
scilab/modules/jvm/LibScilab_Import.def
scilab/modules/jvm/sci_gateway/c/sci_javaclasspath.c
scilab/modules/jvm/sci_gateway/c/sci_javalibrarypath.c
scilab/modules/localization/sci_gateway/c/sci_addtext.c
scilab/modules/pvm/sci_gateway/c/sci_pvm_addhosts.c
scilab/modules/pvm/sci_gateway/c/sci_pvm_delhosts.c
scilab/modules/tclsci/LibScilab_Import.def
scilab/modules/tclsci/sci_gateway/c/sci_TCL_EvalStr.c
scilab/modules/tclsci/sci_gateway/c/sci_TCL_SetVar.c
scilab/modules/tclsci/src/c/TclUiSet.c
scilab/modules/windows_tools/sci_gateway/c/sci_toprint.c
scilab/modules/windows_tools/src/c/LibScilab_Import.def

index c4864e9..fa2bdc1 100644 (file)
@@ -11,6 +11,7 @@
 #include "Scierror.h"
 #include "MALLOC.h"
 #include "sortTemplate.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_gsort) _PARAMS((char *fname, unsigned long fname_len))
 {
@@ -159,6 +160,7 @@ int C2F(sci_gsort) _PARAMS((char *fname, unsigned long fname_len))
                                Str[i]=(char*)MALLOC(sizeof(char)*(strlen(S[i])+1));
                                if (Str[i]) strcpy(Str[i],S[i]);
                        }
+                       freeArrayOfString(S,m1*n1);
                        if (typex[0]==LIST_SORT) {
                          lgsortstring(Str,indices,m1,n1,typex,iord); /* When it is going to be lr or lc*/
                        }
index 2affb56..8c6d134 100644 (file)
@@ -21,6 +21,7 @@ EXPORTS
  gettype_
  vstk_
  callFunctionFromGateway
+ freeArrayOfString
 ;
 ;elementary_functions_f
  dset_
\ No newline at end of file
index a7c7b57..50c3484 100644 (file)
@@ -9,6 +9,7 @@
 #include "MALLOC.h"
 #include "gw_fftw.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 extern unsigned cur_fftw_flags;
 /*--------------------------------------------------------------------------*/
@@ -134,14 +135,8 @@ int sci_fftw_flags __PARAMS((char *fname,unsigned long fname_len))
      }
     }
     cur_fftw_flags = flagv;
-    /* FreeRhsSVar(Str1);*/
-    if (Str1) for (i = 0; i<m1*n1 ;i++) {
-      if (Str1[i]) {
-         FREE(Str1[i]);
-         Str1[i]=NULL;
-      }
-    }
-    if (Str1) {FREE(Str1); Str1=NULL;}
+
+       freeArrayOfString(Str1,m1*n1);
    }
 
    else {
@@ -197,11 +192,8 @@ int sci_fftw_flags __PARAMS((char *fname,unsigned long fname_len))
   }
 
   n1=1;
-  /*CreateVarFromPtr( 3,MATRIX_OF_STRING_DATATYPE, &j, &n1, Str3);*/
   CreateVarFromPtr( Rhs+3,MATRIX_OF_STRING_DATATYPE, &j, &n1, Str3);
 
-  /*LhsVar(1)=2;*/
-  /*LhsVar(2)=3;*/
   LhsVar(1)=Rhs+2;
   LhsVar(2)=Rhs+3;
   PutLhsVar();
index 6212e5d..4171152 100644 (file)
@@ -8,6 +8,7 @@
 #include "MALLOC.h"
 #include "gw_fftw.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 
 /* Set fftw wisdom
@@ -49,15 +50,8 @@ int sci_set_fftw_wisdom __PARAMS((char *fname,unsigned long fname_len))
   }
   Str[k-1] = '\0';
 
-  /*FreeRhsSVar(Str1);*/
-  if (Str1) for (i = 0; i<m1*n1 ;i++) {
-    if (Str1[i]) {
-       FREE(Str1[i]);
-       Str1[i]=NULL;
-    }
-  }
-  if (Str1) {FREE(Str1); Str1=NULL;}
-
+  freeArrayOfString(Str1,m1*n1);
+  
   if(!(call_fftw_import_wisdom_from_string(Str))) {
    Scierror(999,_("%s: FFTW can't read wisdom\n"),
                  fname);
index a625c58..05e109a 100644 (file)
@@ -42,4 +42,5 @@ EXPORTS
  IsAlreadyOpenedInScilab
  getWarningMode
  callFunctionFromGateway
+ freeArrayOfString
  
index 7e002ac..b99472e 100644 (file)
@@ -9,6 +9,7 @@
 #include "fileio.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int int_objfprintfMat(char *fname,unsigned long fname_len)
 {
@@ -96,19 +97,7 @@ int int_objfprintfMat(char *fname,unsigned long fname_len)
        LhsVar(1)=0 ; /** no return value **/
        if ( Rhs >= 4)
        {
-               if (Str2)
-               {
-                       for ( i=0 ; i < mS*nS ; i++)
-                       {
-                               if (Str2[i])
-                               {
-                                       FREE(Str2[i]);
-                                       Str2[i]=NULL;
-                               }
-                       }
-                       FREE(Str2);
-                       Str2=NULL;
-               }
+               freeArrayOfString(Str2,mS*nS);
        }
        PutLhsVar();
        return 0;
index bd6069c..0f1c1bb 100644 (file)
@@ -12,7 +12,7 @@
 #include "BuildObjects.h"
 #include "gw_graphics.h"
 #include "MALLOC.h"
-
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int sci_xstring( char *fname, unsigned long fname_len )
 {
@@ -58,20 +58,8 @@ int sci_xstring( char *fname, unsigned long fname_len )
 
 
   /* we must free Str memory */ 
-  if (Str)
-  {
-         int i=0;
-         for(i=0;i<m3*n3;i++)
-         {
-                 if (Str[i])
-                 {
-                         FREE(Str[i]);
-                         Str[i]=NULL;
-                 }
-         }
-         FREE(Str);
-         Str=NULL;
-  }
+  
+  freeArrayOfString(Str,m3*n3);
 
   LhsVar(1)=0;
   return 0;
index 5361608..a9b6505 100644 (file)
@@ -16,7 +16,7 @@
 #include "GetProperty.h"
 #include "MALLOC.h"
 #include "sciCall.h"
-
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int sci_xstringb(char *fname,unsigned long fname_len)
 {
@@ -69,20 +69,7 @@ int sci_xstringb(char *fname,unsigned long fname_len)
 
   LhsVar(1)=0;
 
-  if (Str)
-  {
-         int i=0;
-         for(i=0;i<m3*n3;i++)
-         {
-                 if (Str[i])
-                 {
-                         FREE(Str[i]);
-                         Str[i]=NULL;
-                 }
-         }
-         FREE(Str);
-         Str=NULL;
-  } 
+  freeArrayOfString(Str,m3*n3);
 
   return 0;
 
index f470045..8dc2220 100644 (file)
@@ -16,7 +16,7 @@
 #include "Axes.h"
 #include "GetProperty.h"
 #include "CurrentObjectsManagement.h"
-
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int sci_xstringl( char *fname, unsigned long fname_len )
 {
@@ -45,6 +45,8 @@ int sci_xstringl( char *fname, unsigned long fname_len )
   *stk(l4+2) = 0.0;
   *stk(l4+3) = 0.0;
 
+  freeArrayOfString(Str,m3*n3);
+
   LhsVar(1)=Rhs+1;
   return 0;
 }
index e29d568..5c8f354 100644 (file)
@@ -19,7 +19,7 @@
 #include "DrawObjects.h"
 #include "MALLOC.h"
 #include "CurrentObjectsManagement.h"
-
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int sci_xtitle( char * fname, unsigned long fname_len )
 {
@@ -97,19 +97,7 @@ int sci_xtitle( char * fname, unsigned long fname_len )
       strcat(C2F(cha1).buf,Str[i]);
     }
 
-       if (Str)
-       {
-               for ( i= 1 ; i < m*n ; i++) 
-               {
-                       if (Str[i])
-                       {
-                               FREE(Str[i]);
-                               Str[i]=NULL;
-                       }
-               }
-               FREE(Str);
-               Str=NULL;
-       }
+       freeArrayOfString(Str,m*n);
 
     switch(narg)
     {
index 8d59565..4d8b2cd 100644 (file)
@@ -13,6 +13,7 @@
 #include "scilabmode.h"
 #include "localization.h"
 #include "IsAScalar.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_ClipBoard) _PARAMS((char *fname,unsigned long l))
 {
@@ -155,6 +156,7 @@ int C2F(sci_ClipBoard) _PARAMS((char *fname,unsigned long l))
                                                if(TextToSendInClipboard) {FREE(TextToSendInClipboard);TextToSendInClipboard=NULL;}
                                        }
 
+                                       freeArrayOfString(Str,m1*n1);
                                        m1=0;
                                        n1=0;
                                        l1=0;
index 250ff3d..8abefba 100644 (file)
@@ -19,5 +19,6 @@ callFunctionFromGateway
 SetFunction
 vartype_
 sciReturnString
+freeArrayOfString
 ;
 
index 7d01710..f19dc76 100644 (file)
@@ -10,6 +10,7 @@
 #include "HistoryManager.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_addhistory) _PARAMS((char *fname,unsigned long fname_len))
 {
@@ -27,8 +28,9 @@ int C2F(sci_addhistory) _PARAMS((char *fname,unsigned long fname_len))
                bOK = appendLinesToScilabHistory(lines,m1*n1);
 
                LhsVar(1) = 0;
-               C2F(putlhsvar)();       
+               C2F(putlhsvar)();
 
+               freeArrayOfString(lines, m1*n1);
        }
        else
        {
index 96a7ffa..f3b4da8 100644 (file)
@@ -7,6 +7,7 @@
 #include "systemc.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_host) _PARAMS((char *fname,unsigned long fname_len))
 {
@@ -22,6 +23,7 @@ int C2F(sci_host) _PARAMS((char *fname,unsigned long fname_len))
 
                if ( (m1 != 1) && (n1 != 1) )
                {
+                       freeArrayOfString(Str,m1*n1);
                        Scierror(89,_("Input argument has incorrect dimensions.\n"));
                        return 0;
                }
@@ -37,6 +39,7 @@ int C2F(sci_host) _PARAMS((char *fname,unsigned long fname_len))
 
                        LhsVar(1)= Rhs+1;
                        C2F(putlhsvar)();
+                       freeArrayOfString(Str,m1*n1);
                }
        }
        else
index 16ca005..4b27270 100644 (file)
@@ -14,6 +14,7 @@
 #include "cluni0.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int GetIndexLastModifiedFileInList(char **ListFilename,int numberelemnts);
 /*--------------------------------------------------------------------------*/
@@ -87,6 +88,7 @@ int C2F(sci_newest) _PARAMS((char *fname,unsigned long fname_len))
                                return 0;
                        }
                        RetIndex=GetIndexLastModifiedFileInList(Str,m1*n1);
+                       freeArrayOfString(Str,m1*n1);
                }
                else
                {
@@ -104,16 +106,8 @@ int C2F(sci_newest) _PARAMS((char *fname,unsigned long fname_len))
                        }
 
                        RetIndex=GetIndexLastModifiedFileInList(Str,RhsBackup);
-                       if (Str)
-                       {
-                               for (j=1;j<=RhsBackup;j++)
-                               {
-                                       FREE(Str[j-1]);
-                                       Str[j-1]=NULL;
-                               }
-                               FREE(Str);
-                               Str=NULL;
-                       }
+
+                       freeArrayOfString(Str,RhsBackup);
                }
 
                if (RetIndex>=1)
index 76ed6f1..d80d7f2 100644 (file)
@@ -25,5 +25,6 @@ EXPORTS
  scigetcwd_
  vartype_
  callFunctionFromGateway
+ freeArrayOfString
 ;
 
index 2d6c364..da1fbb5 100644 (file)
@@ -19,4 +19,5 @@ EXPORTS
  createvarfromptr_
  GetXmlFileEncoding
  callFunctionFromGateway
+ freeArrayOfString
 ;
index b13162f..e17a1bb 100644 (file)
@@ -11,6 +11,7 @@
 #include "addToClasspath.h"
 #include "getClasspath.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_javaclasspath) _PARAMS((char *fname,unsigned long fname_len))
 {
@@ -30,20 +31,7 @@ int C2F(sci_javaclasspath) _PARAMS((char *fname,unsigned long fname_len))
 
                LhsVar(1)=Rhs+1;
                C2F(putlhsvar)();
-               if (Strings)
-               {
-                       for (i=0;i<nbRow;i++)
-                       {
-                               if (Strings[i])
-                               {
-                                       FREE(Strings[i]);
-                                       Strings[i]=NULL;
-                               }
-                       }
-                       FREE(Strings);
-                       Strings=NULL;
-               }
-
+               freeArrayOfString(Strings,nbRow*nbCol);
        }
        else
        {
@@ -61,12 +49,14 @@ int C2F(sci_javaclasspath) _PARAMS((char *fname,unsigned long fname_len))
                                bOK=addToClasspath(CLASSPATHS[i]);
                                if (!bOK)
                                {
+                                       freeArrayOfString(CLASSPATHS,m1*n1);
                                        Scierror(999,_("could not add URL to system classloader : %s.\n"),CLASSPATHS[i]);
                                        return 0;
                                }
                        }
                        LhsVar(1) = 0;
                        C2F(putlhsvar)();       
+                       freeArrayOfString(CLASSPATHS,m1*n1);
                }
                else
                {
index bd889d6..600b11c 100644 (file)
@@ -11,6 +11,7 @@
 #include "addToLibrarypath.h"
 #include "getLibrarypath.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_javalibrarypath) _PARAMS((char *fname,unsigned long fname_len))
 {
@@ -30,20 +31,7 @@ int C2F(sci_javalibrarypath) _PARAMS((char *fname,unsigned long fname_len))
 
                LhsVar(1)=Rhs+1;
                C2F(putlhsvar)();
-               if (Strings)
-               {
-                       for (i=0;i<nbRow;i++)
-                       {
-                               if (Strings[i])
-                               {
-                                       FREE(Strings[i]);
-                                       Strings[i]=NULL;
-                               }
-                       }
-                       FREE(Strings);
-                       Strings=NULL;
-               }
-
+               freeArrayOfString(Strings,nbRow*nbCol);
        }
        else
        {
@@ -61,12 +49,14 @@ int C2F(sci_javalibrarypath) _PARAMS((char *fname,unsigned long fname_len))
                                bOK=addToLibrarypath(LIBRARYPATHS[i]);
                                if (!bOK)
                                {
+                                       freeArrayOfString(LIBRARYPATHS,m1*n1);
                                        Scierror(999,_("could not add path to java.library.path : %s.\n"),LIBRARYPATHS[i]);
                                        return 0;
                                }
                        }
                        LhsVar(1) = 0;
                        C2F(putlhsvar)();       
+                       freeArrayOfString(LIBRARYPATHS,m1*n1);
                }
                else
                {
index 3f7823d..693a70d 100644 (file)
@@ -8,6 +8,7 @@
 #include "gw_localization.h"
 #include "Scierror.h"
 #include "MALLOC.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 static struct hashtable *GetLocalizationHashTable(char *param1);
 /*--------------------------------------------------------------------------*/
@@ -57,6 +58,8 @@ int C2F(sci_addtext) _PARAMS((char *fname,unsigned long fname_len))
                                                }
                                        }
 
+                                       freeArrayOfString(param2,m2*n2);
+                                       freeArrayOfString(param3,m3*n3);
                                        /* it is okay ;) */
                                        n1=1;
                                        CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
index 7e6feff..6e48723 100644 (file)
@@ -6,6 +6,7 @@
 /*--------------------------------------------------------------------------*/ 
 #include "gw_pvm.h"
 #include "sci_pvm.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/ 
 /******************************************
  * SCILAB function : pvm_addhosts, fin = 10
@@ -23,6 +24,7 @@ int intspvm_addhosts _PARAMS((char *fname,unsigned long fname_len))
   CreateVar(Rhs+2,MATRIX_OF_INTEGER_DATATYPE,(un=1,&un),(mn2=n1,&mn2),&l2);/* named: infos */
   pvm_addhosts(Str1,n1 ,istk(l2));
 
+  freeArrayOfString(Str1,m1*n1);
   LhsVar(1)= Rhs+2;
   C2F(putlhsvar)();
   return 0;
index 6097dc2..45693ef 100644 (file)
@@ -6,6 +6,7 @@
 /*--------------------------------------------------------------------------*/ 
 #include "gw_pvm.h"
 #include "sci_pvm.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/ 
 /******************************************
  * SCILAB function : pvm_delhosts, fin = 11
@@ -22,6 +23,7 @@ int intspvm_delhosts _PARAMS((char *fname,unsigned long fname_len))
   /* cross variable size checking */
   CreateVar(Rhs+2,MATRIX_OF_INTEGER_DATATYPE,(un=1,&un),(mn2=n1,&mn2),&l2);/* named: infos */
   pvm_delhosts(Str1, n1,istk(l2));
+  freeArrayOfString(Str1,m1,n1);
   LhsVar(1)= Rhs+2;
   C2F(putlhsvar)();
   return 0;
index 589a741..8cc6bbb 100644 (file)
@@ -22,4 +22,5 @@ EXPORTS
  createvarfromptr_
  getSCIpath
  callFunctionFromGateway
- scilab_timer_check
\ No newline at end of file
+ scilab_timer_check
+ freeArrayOfString
\ No newline at end of file
index 9efebb9..1be28cd 100644 (file)
@@ -6,6 +6,7 @@
 #include "gw_tclsci.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
 { 
@@ -25,6 +26,7 @@ int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
 
                if (TCLinterp == NULL)
                {
+                       freeArrayOfString(Str,m1*n1);
                        Scierror(999,_("%s : Error main TCL interpreter not initialized.\n"),fname);
                        return 0;
                }
@@ -38,12 +40,14 @@ int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
                                TCLinterpreter=Tcl_GetSlave(TCLinterp,cstk(l2));
                                if (TCLinterpreter==NULL)
                                {
+                                       freeArrayOfString(Str,m1*n1);
                                        Scierror(999,_("%s: No such slave interpreter.\n"),fname);
                                        return 0;
                                }
                        }
                        else
                        {
+                               freeArrayOfString(Str,m1*n1);
                                Scierror(999,_("%s : Argument type must be character string.\n"),fname);
                                 return 0;
                        }
@@ -66,6 +70,7 @@ int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
                        if (RET==TCL_ERROR)
                        {
                 const char *trace = Tcl_GetVar(TCLinterpreter, "errorInfo", TCL_GLOBAL_ONLY);
+                               freeArrayOfString(Str,m1*n1);
                                if(Err>0)
                                {
                                        Scierror(999,"%s, ScilabEval error at line %i\n %s.\n",fname,i+1,(char *)trace);
@@ -74,17 +79,10 @@ int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
                                {
                                        Scierror(999,"%s, %s at line %i\n       %s\n",fname,TCLinterpreter->result,i+1,(char *)trace);
                                }
-                               if (Str) for (i = 0; i<m1*n1 ;i++)
-                               {
-                                       if (Str[i]) 
-                                       {
-                                               FREE(Str[i]);
-                                               Str[i]=NULL;
-                                       }
-                               }
-                               if (Str) {FREE(Str); Str=NULL;}
                                return 0;
-            } else {
+            } 
+                       else
+                       {
                 /* return result of the successful evaluation of the script */
                 /* return a matrix of string results */
                 RetStr = (char*)Tcl_GetStringResult(TCLinterpreter);
@@ -98,6 +96,7 @@ int C2F(sci_TCL_EvalStr) _PARAMS((char *fname,unsigned long l))
 
                for (i=0;i<n1;i++) for (j=0;j<m1;j++) { FREE(ReturnArrayString[i+n1*j]);ReturnArrayString[i+n1*j]=NULL; }
                FREE(ReturnArrayString);
+               freeArrayOfString(Str,m1*n1);
        }
        else
        {
index 1d6cf68..d14d719 100644 (file)
@@ -7,6 +7,7 @@
 #include "setvar.h"
 #include "Scierror.h"
 #include "localization.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_TCL_SetVar) _PARAMS((char *fname,unsigned long l))
 {
@@ -71,15 +72,7 @@ int C2F(sci_TCL_SetVar) _PARAMS((char *fname,unsigned long l))
                {
                        *paramoutINT=SetVarStrings(TCLinterpreter,VarName,Str,m1,n1);
                }
-               if (Str) for (i = 0; i<m1*n1 ;i++)
-               {
-                       if (Str[i]) 
-                       {
-                               FREE(Str[i]);
-                               Str[i]=NULL;
-                       }
-               }
-               if (Str) {FREE(Str); Str=NULL;}
+               freeArrayOfString(Str,m1*n1);
        }
        else
        if ( (GetType(1) == sci_strings) && (GetType(2) == sci_matrix) )
index bdab3f0..8d87842 100644 (file)
@@ -6,6 +6,7 @@
 #include "Scierror.h"
 #include "localization.h"
 #include "setvar.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 #define NBRSTYLE 9
 char *UiStyleInternalName[NBRSTYLE] = {"button",
@@ -66,15 +67,7 @@ int InterfaceScilabToUiSet(int Handle,int RhsPropertieField,int RhsPropertieValu
                                        {
                                                SetVarStrings(TCLinterp,VarName,Str,m1,n1);
                                        }
-                                       if (Str) for (i = 0; i<m1*n1 ;i++)
-                                       {
-                                               if (Str[i]) 
-                                               {
-                                                       FREE(Str[i]);
-                                                       Str[i]=NULL;
-                                               }
-                                       }
-                                       if (Str) {FREE(Str); Str=NULL;}
+                                       freeArrayOfString(Str,m1*n1);
                                }
                                else if (GetType(RhsPropertieValue)==sci_matrix)
                                {
@@ -159,15 +152,7 @@ int InterfaceScilabToUiSet(int Handle,int RhsPropertieField,int RhsPropertieValu
                                                                }
                                                        }
                                                }
-                                               if (Str) for (i = 0; i<m1*n1 ;i++)
-                                               {
-                                                       if (Str[i]) 
-                                                       {
-                                                               FREE(Str[i]);
-                                                               Str[i]=NULL;
-                                                       }
-                                               }
-                                               if (Str) {FREE(Str); Str=NULL;}
+                                               freeArrayOfString(Str,m1*n1);
                                                bOK=1;
                                        }
                                        else
index 75ade12..b6c201e 100644 (file)
@@ -11,6 +11,7 @@
 #include "Scierror.h"
 #include "../../../fileio/includes/FileExist.h"
 #include "IsAScalar.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 extern BOOL FigureToPrint(int figurenumber,BOOL Postscript);
 /*--------------------------------------------------------------------------*/
@@ -113,19 +114,7 @@ int C2F(sci_toprint) _PARAMS((char *fname,unsigned long l))
                                                sprintf(lines,"%s%s\n",lines,Str[i]);
                                        }
                                }
-                               if (Str)
-                               {
-                                       for (i = 0; i<m1 ;i++)
-                                       {
-                                               if (Str[i])
-                                               {
-                                                       FREE(Str[i]);
-                                                       Str[i]=NULL;
-                                               }
-                                       }
-                                       FREE(Str);
-                                       Str=NULL;
-                               }
+                               freeArrayOfString(Str,m1);
                        }
                        else
                        if (m1 == 1)
@@ -142,36 +131,11 @@ int C2F(sci_toprint) _PARAMS((char *fname,unsigned long l))
                                        }
                                        else sprintf(lines,"%s%s\n",lines,Str[i]);
                                }
-                               if (Str)
-                               {
-                                       for (i = 0; i<n1 ;i++)
-                                       {
-                                               if (Str[i])
-                                               {
-                                                       FREE(Str[i]);
-                                                       Str[i]=NULL;
-                                               }
-                                       }
-                                       FREE(Str);
-                                       Str=NULL;
-                               }
+                               freeArrayOfString(Str,m1);
                        }
                        else
                        {
-                               if (Str)
-                               {
-                                       int i=0;
-                                       for (i = 0; i<n1 ;i++)
-                                       {
-                                               if (Str[i])
-                                               {
-                                                       FREE(Str[i]);
-                                                       Str[i]=NULL;
-                                               }
-                                       }
-                                       FREE(Str);
-                                       Str=NULL;
-                               }
+                               freeArrayOfString(Str,m1);
                                Scierror(999,"parameter incorrect must be a string or a string matrix (1 x m) or (n x 1).");
                                return 0;
                        }