Add convstr to YaSp 40/3540/6
Bruno JOFRET [Wed, 16 Mar 2011 07:31:09 +0000 (08:31 +0100)]
Change-Id: I2911e8b724073fcaf31a26be9f687f5aa0267036

scilab/modules/string/Makefile.am
scilab/modules/string/Makefile.in
scilab/modules/string/includes/gw_string.h
scilab/modules/string/includes/string_gw.hxx
scilab/modules/string/sci_gateway/c/gw_string.c
scilab/modules/string/sci_gateway/c/sci_convstr.c [deleted file]
scilab/modules/string/sci_gateway/cpp/sci_convstr.cpp [new file with mode: 0644]
scilab/modules/string/sci_gateway/cpp/string_gw.cpp
scilab/modules/string/sci_gateway/cpp/string_gw.vcproj
scilab/modules/string/src/c/string.vcproj

index 664ce54..cd8cb23 100644 (file)
@@ -33,7 +33,6 @@ STRING_FORTRAN_SOURCES =
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
 sci_gateway/c/sci_code2str.c \
-sci_gateway/c/sci_convstr.c \
 sci_gateway/c/sci_str2code.c \
 sci_gateway/c/sci_strsplit.c \
 sci_gateway/c/sci_tokens.c \
@@ -62,7 +61,9 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_strsubst.cpp \
        sci_gateway/cpp/sci_ascii.cpp \
        sci_gateway/cpp/sci_strcat.cpp \
-       sci_gateway/cpp/sci_string.cpp
+       sci_gateway/cpp/sci_string.cpp \
+       sci_gateway/cpp/sci_convstr.cpp
+
 
 GATEWAY_FORTRAN_SOURCES =  sci_gateway/fortran/sci_string.f \
 sci_gateway/fortran/strops.f
index 70731cf..5bd5a1b 100644 (file)
@@ -130,7 +130,7 @@ am__objects_2 = libscistring_la-code2str.lo libscistring_la-convstr.lo \
        libscistring_la-os_wcsdup.lo libscistring_la-scistrtostr.lo
 am__objects_3 =
 am__objects_4 = libscistring_la-gw_string.lo \
-       libscistring_la-sci_code2str.lo libscistring_la-sci_convstr.lo \
+       libscistring_la-sci_code2str.lo \
        libscistring_la-sci_str2code.lo \
        libscistring_la-sci_strsplit.lo libscistring_la-sci_tokens.lo \
        libscistring_la-sci_strcmp.lo libscistring_la-sci_isletter.lo \
@@ -147,7 +147,8 @@ am__objects_6 = libscistring_la-sci_stripblanks.lo \
        libscistring_la-sci_regexp.lo libscistring_la-sci_part.lo \
        libscistring_la-sci_length.lo libscistring_la-sci_strindex.lo \
        libscistring_la-sci_strsubst.lo libscistring_la-sci_ascii.lo \
-       libscistring_la-sci_strcat.lo libscistring_la-sci_string.lo
+       libscistring_la-sci_strcat.lo libscistring_la-sci_string.lo \
+       libscistring_la-sci_convstr.lo
 am_libscistring_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4) $(am__objects_5) \
        $(am__objects_6)
@@ -476,7 +477,6 @@ src/c/scistrtostr.c
 STRING_FORTRAN_SOURCES = 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
 sci_gateway/c/sci_code2str.c \
-sci_gateway/c/sci_convstr.c \
 sci_gateway/c/sci_str2code.c \
 sci_gateway/c/sci_strsplit.c \
 sci_gateway/c/sci_tokens.c \
@@ -505,7 +505,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_strsubst.cpp \
        sci_gateway/cpp/sci_ascii.cpp \
        sci_gateway/cpp/sci_strcat.cpp \
-       sci_gateway/cpp/sci_string.cpp
+       sci_gateway/cpp/sci_string.cpp \
+       sci_gateway/cpp/sci_convstr.cpp
 
 GATEWAY_FORTRAN_SOURCES = sci_gateway/fortran/sci_string.f \
 sci_gateway/fortran/strops.f
@@ -950,13 +951,6 @@ libscistring_la-sci_code2str.lo: sci_gateway/c/sci_code2str.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(libscistring_la_CFLAGS) $(CFLAGS) -c -o libscistring_la-sci_code2str.lo `test -f 'sci_gateway/c/sci_code2str.c' || echo '$(srcdir)/'`sci_gateway/c/sci_code2str.c
 
-libscistring_la-sci_convstr.lo: sci_gateway/c/sci_convstr.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(libscistring_la_CFLAGS) $(CFLAGS) -MT libscistring_la-sci_convstr.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_convstr.Tpo -c -o libscistring_la-sci_convstr.lo `test -f 'sci_gateway/c/sci_convstr.c' || echo '$(srcdir)/'`sci_gateway/c/sci_convstr.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_la-sci_convstr.Tpo $(DEPDIR)/libscistring_la-sci_convstr.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_convstr.c' object='libscistring_la-sci_convstr.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(libscistring_la_CFLAGS) $(CFLAGS) -c -o libscistring_la-sci_convstr.lo `test -f 'sci_gateway/c/sci_convstr.c' || echo '$(srcdir)/'`sci_gateway/c/sci_convstr.c
-
 libscistring_la-sci_str2code.lo: sci_gateway/c/sci_str2code.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(libscistring_la_CFLAGS) $(CFLAGS) -MT libscistring_la-sci_str2code.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_str2code.Tpo -c -o libscistring_la-sci_str2code.lo `test -f 'sci_gateway/c/sci_str2code.c' || echo '$(srcdir)/'`sci_gateway/c/sci_str2code.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_la-sci_str2code.Tpo $(DEPDIR)/libscistring_la-sci_str2code.Plo
@@ -1174,6 +1168,13 @@ libscistring_la-sci_string.lo: sci_gateway/cpp/sci_string.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscistring_la-sci_string.lo `test -f 'sci_gateway/cpp/sci_string.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_string.cpp
 
+libscistring_la-sci_convstr.lo: sci_gateway/cpp/sci_convstr.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscistring_la-sci_convstr.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_convstr.Tpo -c -o libscistring_la-sci_convstr.lo `test -f 'sci_gateway/cpp/sci_convstr.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_convstr.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscistring_la-sci_convstr.Tpo $(DEPDIR)/libscistring_la-sci_convstr.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_convstr.cpp' object='libscistring_la-sci_convstr.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscistring_la-sci_convstr.lo `test -f 'sci_gateway/cpp/sci_convstr.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_convstr.cpp
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
index bb120c7..8b5e4ac 100644 (file)
@@ -22,7 +22,7 @@ STRING_IMPEXP int gw_string(void);
 /*--------------------------------------------------------------------------*/
 //STRING_IMPEXP int sci_length(char *fname,unsigned long fname_len); -> C++
 //STRING_IMPEXP int sci_string(char *fname,unsigned long fname_len); -> C++
-STRING_IMPEXP int sci_convstr(char *fname,unsigned long fname_len);
+//STRING_IMPEXP int sci_convstr(char *fname,unsigned long fname_len); -> C++
 STRING_IMPEXP int sci_str2code(char *fname,unsigned long fname_len);
 STRING_IMPEXP int sci_code2str(char *fname,unsigned long fname_len);
 STRING_IMPEXP int sci_tokens(char *fname,unsigned long fname_len);
index 373defb..8f62d49 100644 (file)
@@ -38,6 +38,7 @@ CPP_GATEWAY_PROTOTYPE(sci_strsubst);
 CPP_GATEWAY_PROTOTYPE(sci_ascii);
 CPP_GATEWAY_PROTOTYPE(sci_strcat);
 CPP_GATEWAY_PROTOTYPE(sci_string);
+CPP_GATEWAY_PROTOTYPE(sci_convstr);
 
 
 #endif /* !__STRING_GW_HXX__ */
index 33a8312..e970d96 100644 (file)
@@ -22,7 +22,7 @@ static gw_generic_table Tab[] =
        {NULL, ""}, //length
        {NULL, ""}, //part
        {NULL,""}, //string
-       {sci_convstr,"convstr"},
+       {NULL,""}, //convstr
        {NULL, ""}, //emptystr
        {sci_str2code,"str2code"},
        {sci_code2str,"code2str"},
diff --git a/scilab/modules/string/sci_gateway/c/sci_convstr.c b/scilab/modules/string/sci_gateway/c/sci_convstr.c
deleted file mode 100644 (file)
index 6caa556..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA - Cong WU
- * 
- * 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
- *
- */
-
-/* desc : converts the matrix of strings  str-matrix  into lower case (for*/  
-/*          "l"  ;default value) or upper case (for  "u" ).               */
-/*        [y]=convstr(str-matrix, ["flag"])                               */
-/*              str-matrix, y : matrices of strings                       */
-/*              "flag"  : string ( "u"  for upper or  "l"  for lower      */
-/*                        (default value))                                */
-/*------------------------------------------------------------------------*/
-#include <string.h>
-#include <stdio.h>
-#include "gw_string.h"
-#include "stack-c.h"
-#include "MALLOC.h"
-#include "convstr.h"
-#include "localization.h"
-#include "Scierror.h"
-#include "freeArrayOfString.h"
-/*----------------------------------------------------------------------------*/
-int sci_convstr(char *fname,unsigned long fname_len)
-{
-       char **Input_Matrix = NULL;
-       char **Output_Matrix = NULL;
-       char typ = LOW;
-       int numRow = 0;
-       int numCol = 0;
-       int Row_Num_One = 0;
-       int Col_Num_One = 0;
-       int mn = 0; /* Row_Num_One * Col_Num_One */
-       int i = 0;
-       
-       int Type_One = 0;
-       
-       CheckRhs(1,2);
-       CheckLhs(1,1);
-       
-       Type_One = VarType(1);
-       
-       if (Rhs == 2) 
-       {
-               int Type_Two = VarType(2);
-               
-               if (Type_Two == sci_strings) 
-               {
-                       int Row_Num_Two = 0,Col_Num_Two = 0,Stack_Pos=0;
-                       
-                       GetRhsVar(2,STRING_DATATYPE,&Row_Num_Two,&Col_Num_Two,&Stack_Pos);
-                       if ( (Row_Num_Two*Col_Num_Two) == 1 )
-                       {
-                               /* To put "flag" into typ; whether "u" or "l" */
-                               typ = cstk(Stack_Pos)[0];
-                               if ( (typ != UPPER) && (typ != LOW) && (typ != UPPER_B) && (typ != LOW_B) ) 
-                               {
-                                       Scierror(999,_("%s: Wrong value for input argument #%d: 'u' (Upper) or 'l' (Lower) expected.\n"),fname,2);
-                                       return 0;
-                               }
-                       }
-                       else
-                       {
-                               Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
-                               return 0;
-                       }
-               }
-               else
-               {
-                       Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
-                       return 0;
-               }
-       }
-       
-       switch (Type_One) 
-       {
-               case sci_strings :
-               {
-                       GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_Num_One,&Col_Num_One,&Input_Matrix);     /* To input the string matrix */
-                       mn = Row_Num_One * Col_Num_One; 
-               }
-               break;
-               case sci_matrix :
-               {
-                       GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&Row_Num_One,&Col_Num_One,&Input_Matrix);
-            if ( (Row_Num_One == 0) && (Col_Num_One == 0) )
-                       {
-                               int l =0;
-                               CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,&Row_Num_One,&Col_Num_One,&l);
-                               LhsVar(1) = Rhs+1 ;
-                               C2F(putlhsvar)();
-                               return 0;
-                       }
-                       else 
-                       {
-                               Scierror(999,_("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"),fname,1);
-                               return 0;
-                       }
-               }
-               break;
-               default :
-                       Scierror(999,_("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"),fname,1);
-                       return 0;
-               break;
-       }
-       
-       Output_Matrix = (char**)MALLOC(sizeof(char*)*(mn));
-       if (Output_Matrix == NULL)
-       {
-               Scierror(999,_("%s: No more memory.\n"),fname);
-               return 0;
-       }
-       
-       for (i = 0;i < mn;i++)
-       {
-               Output_Matrix[i] = (char*)MALLOC( sizeof(char*) * (strlen(Input_Matrix[i])+1) );
-               if (Output_Matrix[i] == NULL)
-               {
-                       freeArrayOfString(Output_Matrix,i);
-                       Scierror(999,("%s: No more memory.\n"),fname);
-                       return 0;
-               }
-       }
-       
-       /* convstr algorithm */
-       convstr(Input_Matrix,Output_Matrix,typ,mn); 
-       freeArrayOfString(Input_Matrix,mn);
-       
-       /* put on scilab stack */
-       numRow   = Row_Num_One; 
-       numCol   = Col_Num_One ;
-       CreateVarFromPtr( Rhs+1,MATRIX_OF_STRING_DATATYPE, &numRow, &numCol, Output_Matrix );
-       LhsVar(1) = Rhs+1 ;
-       C2F(putlhsvar)();
-       
-       /* free pointers used */
-       freeArrayOfString(Output_Matrix,mn);
-       return 0;
-}
-/*--------------------------------------------------------------------------*/ 
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_convstr.cpp b/scilab/modules/string/sci_gateway/cpp/sci_convstr.cpp
new file mode 100644 (file)
index 0000000..9c42113
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "string_gw.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "double.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+}
+
+using namespace types;
+
+Function::ReturnValue sci_convstr(typed_list &in, int _iRetCount, typed_list &out)
+{
+    int iConvertMode = -1; // Default is TO_LOWER
+
+    if (_iRetCount != 1)
+    {
+        ScierrorW(78, _W("%ls: Wrong number of output argument(s): %d expected.\n"), L"convstr", 1);
+        return Function::Error;
+    }
+
+    if (in.size() != 1 && in.size() != 2)
+    {
+        ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d or %d expected.\n"), L"convstr", 1, 2);
+        return Function::Error;
+    }
+
+    if (in[0]->isString() == false && !(in[0]->isDouble() == true && in[0]->getAs<Double>()->isEmpty() == true))
+    {
+        ScierrorW(999, _W("%ls: Wrong type for input argument #%d: Matrix of strings expected.\n"), L"convstr", 2);
+        return Function::Error;
+    }
+
+    if (in.size() == 2 && in[1]->isString() == true)
+    {
+        String *pInConvertMode = in[1]->getAs<String>();
+        if (pInConvertMode->getSize() != 1 || wcslen(pInConvertMode->get(0)) != 1)
+        {
+            ScierrorW(999, _W("%ls: Wrong value for input argument #%d: 'u' (Upper) or 'l' (Lower) expected.\n"), L"convstr", 2);
+            return Function::Error;
+        }
+
+        wchar_t wcConvertMode = pInConvertMode->get(0)[0];
+        if (wcConvertMode == L'l' ||wcConvertMode == L'L' )
+        {
+            iConvertMode = -1;
+        }
+        else if(wcConvertMode == L'u' || wcConvertMode == L'U')
+        {
+            iConvertMode = 1;
+        }
+        else
+        {
+            ScierrorW(999, _W("%ls: Wrong value for input argument #%d: 'u' (Upper) or 'l' (Lower) expected.\n"), L"convstr", 2);
+            return Function::Error;
+        }
+    }
+
+    // Special case convstr([], *) == []
+    if(in[0]->isDouble())
+    {
+        out.push_back(Double::Empty());
+        return Function::OK;
+    }
+
+
+    String *pstConvertMe = static_cast<String *>(in[0]->getAs<String>()->clone());
+
+    for (int i = 0 ; i < pstConvertMe->getSize() ; ++i)
+    {
+        wchar_t *pwcsCurrent = pstConvertMe->get(i);
+        for(int j = 0 ; j < wcslen(pwcsCurrent) ; ++j)
+        {
+            if(iConvertMode == 1)
+            {
+                pwcsCurrent[j] = towupper(pwcsCurrent[j]);
+            }
+            else
+            {
+                pwcsCurrent[j] = towlower(pwcsCurrent[j]);
+            }
+        }
+    }
+
+    out.push_back(pstConvertMe);
+
+    return Function::OK;
+}
index 4737cbc..c1f7327 100644 (file)
@@ -31,5 +31,6 @@ bool StringModule::Load()
     symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"ascii", &sci_ascii, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"strcat", &sci_strcat, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"string", &sci_string, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(types::Function::createFunction(L"convstr", &sci_convstr, MODULE_NAME));
     return true;
 }
index 2804741..a5d8c8c 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\sci_convstr.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_grep.cpp"
                                >
                        </File>
index 219802a..1775f57 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath="..\..\sci_gateway\c\sci_convstr.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\c\sci_isalphanum.c"
                                >
                        </File>