add function ascii 79/2479/3
Antoine ELIAS [Mon, 15 Nov 2010 15:56:26 +0000 (16:56 +0100)]
Change-Id: I50c53e90597a49e9611b29e10bf3976cf90b7669

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_ascii.c [deleted file]
scilab/modules/string/sci_gateway/cpp/sci_ascii.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 10d5847..d935b98 100644 (file)
@@ -32,7 +32,6 @@ src/c/scistrtostr.c
 STRING_FORTRAN_SOURCES =
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
-sci_gateway/c/sci_ascii.c \
 sci_gateway/c/sci_code2str.c \
 sci_gateway/c/sci_convstr.c \
 sci_gateway/c/sci_str2code.c \
@@ -63,7 +62,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_part.cpp \
        sci_gateway/cpp/sci_length.cpp \
        sci_gateway/cpp/sci_strindex.cpp \
-       sci_gateway/cpp/sci_strsubst.cpp
+       sci_gateway/cpp/sci_strsubst.cpp \
+       sci_gateway/cpp/sci_ascii.cpp
 
 GATEWAY_FORTRAN_SOURCES =  sci_gateway/fortran/sci_string.f \
 sci_gateway/fortran/strops.f
index 02907c7..e698d37 100644 (file)
@@ -132,12 +132,11 @@ 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_ascii.lo libscistring_la-sci_code2str.lo \
-       libscistring_la-sci_convstr.lo libscistring_la-sci_str2code.lo \
-       libscistring_la-sci_strcat.lo libscistring_la-sci_string.lo \
-       libscistring_la-sci_strsplit.lo libscistring_la-sci_tokens.lo \
-       libscistring_la-sci_strcmp.lo libscistring_la-sci_isletter.lo \
-       libscistring_la-sci_isdigit.lo \
+       libscistring_la-sci_code2str.lo libscistring_la-sci_convstr.lo \
+       libscistring_la-sci_str2code.lo libscistring_la-sci_strcat.lo \
+       libscistring_la-sci_string.lo libscistring_la-sci_strsplit.lo \
+       libscistring_la-sci_tokens.lo libscistring_la-sci_strcmp.lo \
+       libscistring_la-sci_isletter.lo libscistring_la-sci_isdigit.lo \
        libscistring_la-sci_isalphanum.lo \
        libscistring_la-sci_isascii.lo libscistring_la-sci_strchr.lo \
        libscistring_la-sci_strcspn.lo libscistring_la-sci_strncpy.lo \
@@ -149,7 +148,7 @@ am__objects_6 = libscistring_la-sci_stripblanks.lo \
        libscistring_la-sci_grep.lo libscistring_la-string_gw.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_strsubst.lo libscistring_la-sci_ascii.lo
 am_libscistring_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3) $(am__objects_4) $(am__objects_5) \
        $(am__objects_6)
@@ -470,7 +469,6 @@ src/c/scistrtostr.c
 
 STRING_FORTRAN_SOURCES = 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
-sci_gateway/c/sci_ascii.c \
 sci_gateway/c/sci_code2str.c \
 sci_gateway/c/sci_convstr.c \
 sci_gateway/c/sci_str2code.c \
@@ -501,7 +499,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_part.cpp \
        sci_gateway/cpp/sci_length.cpp \
        sci_gateway/cpp/sci_strindex.cpp \
-       sci_gateway/cpp/sci_strsubst.cpp
+       sci_gateway/cpp/sci_strsubst.cpp \
+       sci_gateway/cpp/sci_ascii.cpp
 
 GATEWAY_FORTRAN_SOURCES = sci_gateway/fortran/sci_string.f \
 sci_gateway/fortran/strops.f
@@ -940,13 +939,6 @@ libscistring_la-gw_string.lo: sci_gateway/c/gw_string.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-gw_string.lo `test -f 'sci_gateway/c/gw_string.c' || echo '$(srcdir)/'`sci_gateway/c/gw_string.c
 
-libscistring_la-sci_ascii.lo: sci_gateway/c/sci_ascii.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_ascii.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_ascii.Tpo -c -o libscistring_la-sci_ascii.lo `test -f 'sci_gateway/c/sci_ascii.c' || echo '$(srcdir)/'`sci_gateway/c/sci_ascii.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_la-sci_ascii.Tpo $(DEPDIR)/libscistring_la-sci_ascii.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_ascii.c' object='libscistring_la-sci_ascii.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_ascii.lo `test -f 'sci_gateway/c/sci_ascii.c' || echo '$(srcdir)/'`sci_gateway/c/sci_ascii.c
-
 libscistring_la-sci_code2str.lo: sci_gateway/c/sci_code2str.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_code2str.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_code2str.Tpo -c -o libscistring_la-sci_code2str.lo `test -f 'sci_gateway/c/sci_code2str.c' || echo '$(srcdir)/'`sci_gateway/c/sci_code2str.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_la-sci_code2str.Tpo $(DEPDIR)/libscistring_la-sci_code2str.Plo
@@ -1178,6 +1170,13 @@ libscistring_la-sci_strsubst.lo: sci_gateway/cpp/sci_strsubst.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_strsubst.lo `test -f 'sci_gateway/cpp/sci_strsubst.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_strsubst.cpp
 
+libscistring_la-sci_ascii.lo: sci_gateway/cpp/sci_ascii.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_ascii.lo -MD -MP -MF $(DEPDIR)/libscistring_la-sci_ascii.Tpo -c -o libscistring_la-sci_ascii.lo `test -f 'sci_gateway/cpp/sci_ascii.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_ascii.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscistring_la-sci_ascii.Tpo $(DEPDIR)/libscistring_la-sci_ascii.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_ascii.cpp' object='libscistring_la-sci_ascii.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_ascii.lo `test -f 'sci_gateway/cpp/sci_ascii.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_ascii.cpp
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
index 8327188..e4590c7 100644 (file)
@@ -25,7 +25,6 @@ STRING_IMPEXP int sci_convstr(char *fname,unsigned long fname_len);
 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_strcat(char *fname,unsigned long fname_len);
-STRING_IMPEXP int sci_ascii(char *fname,unsigned long fname_len);
 STRING_IMPEXP int sci_tokens(char *fname,unsigned long fname_len);
 STRING_IMPEXP int sci_strcmp(char *fname,unsigned long fname_len);
 STRING_IMPEXP int sci_isletter(char *fname,unsigned long fname_len);
index ef591b9..a33f405 100644 (file)
@@ -34,6 +34,7 @@ CPP_GATEWAY_PROTOTYPE(sci_part);
 CPP_GATEWAY_PROTOTYPE(sci_length);
 CPP_GATEWAY_PROTOTYPE(sci_strindex);
 CPP_GATEWAY_PROTOTYPE(sci_strsubst);
+CPP_GATEWAY_PROTOTYPE(sci_ascii);
 
 
 #endif /* !__STRING_GW_HXX__ */
index e599a0b..0772619 100644 (file)
@@ -29,7 +29,7 @@ static gw_generic_table Tab[] =
        {sci_strcat,"strcat"},
        {NULL, ""}, //strindex
        {NULL, ""}, //strsubst
-       {sci_ascii,"ascii"},
+       {NULL, ""}, //ascii
        {NULL, ""}, //grep
        {sci_tokens,"tokens"},
        {NULL, ""}, //strsplit
diff --git a/scilab/modules/string/sci_gateway/c/sci_ascii.c b/scilab/modules/string/sci_gateway/c/sci_ascii.c
deleted file mode 100644 (file)
index ff2dae2..0000000
+++ /dev/null
@@ -1,332 +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 : This function convert Scilab string to a vector of ascii code  */
-/*        or vector of ascii code to Scilab strings.                     */
-/*        If  txt  is a matrix of string,  ascii(txt)  is equivalent to  */  
-/*          ascii(strcat(txt))                                           */
-/*-----------------------------------------------------------------------*/
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include "gw_string.h"
-#include "stack-c.h"
-#include "MALLOC.h"
-#include "Scierror.h"
-#include "localization.h"
-#include "freeArrayOfString.h"
-#include "getfastcode.h"
-#include "sci_warning.h"
-#include "sciprint.h"
-/*----------------------------------------------------------------------------*/
-static int asciiStrings(char *fname);
-static int asciiMatrix(char *fname);
-static int asciiIntMatrix(char *fname);
-static int asciiOthers(char *fname);
-/*----------------------------------------------------------------------------*/
-#define ASCII_MIN 0
-#define ASCII_MAX 255
-/*----------------------------------------------------------------------------*/
-int sci_ascii(char *fname,unsigned long fname_len)
-{
-       CheckRhs(1,1);
-       CheckLhs(0,1);
-
-       switch ( GetType(1)) 
-       {
-               case sci_strings:
-                       asciiStrings(fname);
-               break;
-
-               case sci_matrix :
-                       asciiMatrix(fname);
-               break;
-               
-               case sci_ints :
-                       asciiIntMatrix(fname);
-               break;
-               
-               default:
-                       asciiOthers(fname);
-               break;
-  }
-  return 0;
-}
-/*--------------------------------------------------------------------------*/
-static int asciiStrings(char *fname)
-{
-       /* interface written with stack3 */
-       /* 3 phases :
-                1] get data from stack 
-                       conversion scilab code to ascii and strings (char **)
-                2] algo. conversion ascii to values
-                3] put results on stack
-       */
-
-       /* interface written with stack1*/
-       /* it works immediately on stack (read and write)
-       conversion scilab code to ascii values 
-       */
-
-       /* Benchmark 
-       str_test_mat =  ["abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz", ..
-       "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"; ..
-       "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz", ..
-       "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"];
-
-       tic();
-       for i=1:10000000
-       ascii(["abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"]);
-       end
-       duree = toc();
-
-       printf("\nDUREE 1 = %d seconds\n\n",duree);
-       */
-
-       /* on windows C2D 6600 2400 mhz */
-       /* scilab 4.1.2 : 40 s */
-       /* scilab with stack3 interface : 75 s*/
-       /* scilab with stack1 interface : 41 s */
-
-/*
-       char **Input_StringMatrix = NULL;
-       int x = 0,y = 0,Row_Num = 0,Col_Num = 0;
-
-       int Length_Output_Matrix = 0;
-       double *Output_IntMatrix = NULL;
-       int nbOutput_IntMatrix = 0;
-       int numRow = 1;
-
-       GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_Num,&Col_Num,&Input_StringMatrix);
-
-       Length_Output_Matrix = 0;
-       for (x = 0;x < Row_Num*Col_Num;x++) Length_Output_Matrix = Length_Output_Matrix + (int)strlen(Input_StringMatrix[x]);
-
-       if (Length_Output_Matrix !=0) 
-       {
-               Output_IntMatrix = (double*)MALLOC(sizeof(double)*(Length_Output_Matrix));
-       }
-       else Output_IntMatrix = (double*)MALLOC(sizeof(double));
-
-       if (Output_IntMatrix == NULL)
-       {
-               freeArrayOfString(Input_StringMatrix,Row_Num*Col_Num);
-               Scierror(999,_("%s: Memory allocation error.\n"),fname);
-               return 0;
-       }
-
-       for (x = 0; x < Row_Num*Col_Num; x++) 
-       {
-               for (y = 0;y < (int)strlen(Input_StringMatrix[x]); y++)
-               {
-                       Output_IntMatrix[nbOutput_IntMatrix]=Input_StringMatrix[x][y];
-                       nbOutput_IntMatrix++;
-               }
-       }
-
-       freeArrayOfString(Input_StringMatrix,Row_Num*Col_Num);
-
-       
-       CreateVarFromPtr(Rhs + 1,MATRIX_OF_DOUBLE_DATATYPE,&numRow,&nbOutput_IntMatrix,&Output_IntMatrix);
-
-       LhsVar(1) = Rhs + 1 ;
-       C2F(putlhsvar)();
-       if (Output_IntMatrix) { FREE(Output_IntMatrix); Output_IntMatrix=NULL;}
-       return 0;
-*/
-
-       BOOL is_a_reference_on_stack = FALSE; /* variable is a reference on stack */
-       int i = 0, j = 0;
-       int nbr_characters  = 0;
-       int  l = 0, il = 0, lr = 0;
-       int ilr = 0;
-
-       il = iadr( C2F(vstk).lstk[Top - 1] );
-
-       ilr = il;
-       if (*istk(il) < 0) 
-       {
-               il = iadr(*istk(il+1));
-       }
-       /* check if parameter is a reference */
-       is_a_reference_on_stack = (il != ilr);
-
-       /* find number of characters */
-       nbr_characters = *istk(il + 4 + *istk(il + 1) * *istk(il + 2)) - 1;
-
-       l = il + 5 + *istk(il+1) * *istk(il+2);
-
-       if (is_a_reference_on_stack) 
-       {
-               /* it is a reference on stack : txt = 'Scilab' ; ascii(txt) */
-               j = ilr + 4;
-               Err = j / 2 + 1 + nbr_characters - C2F(vstk).lstk[Bot - 1];
-               if (Err > 0) 
-               {
-                       /* stacksize exceeded */
-                       SciError(17);
-                       return 0;
-               }
-       } 
-       else 
-       {
-               /* it is not a reference on stack  ascii('Scilab') */
-               int one = 1;
-               int lw = l + nbr_characters;
-
-               j = lw + nbr_characters;
-               Err = j / 2 + 1 - C2F(vstk).lstk[Bot - 1];
-               if (Err > 0) 
-               {
-                       /* stacksize exceeded */
-                       SciError(17);
-                       return 0;
-               }
-               C2F(icopy)(&nbr_characters, istk(l), &one, istk(l + nbr_characters), &one);
-               l = lw;
-       }
-
-       /* create output int matrix , see C2F(crematvar) stack1.c */
-       *istk(ilr) = sci_matrix;
-       *istk(ilr+1) = 1;
-       *istk(ilr+2) = nbr_characters;
-       *istk(ilr+3) = 0;
-
-       j = ilr + 4;
-       lr = j / 2 + 1;
-
-       /* put each value on stack */
-       for (i = 0; i < nbr_characters; i++) 
-       {
-               int scilab_code = *istk(l + i);
-               *stk(lr + i) = convertScilabCodeToAsciiCode(scilab_code);
-       }
-       /* update Top of stack */
-       C2F(vstk).lstk[Top] = lr + nbr_characters;
-
-       return 0;
-       
-}
-/*--------------------------------------------------------------------------*/
-static int asciiMatrix(char *fname)
-{
-       int Row_Num = 0,Col_Num = 0,Stack_Pos = 0;
-       int outIndex = 0 ;
-       int len = 0;
-       BOOL FirstWarning = TRUE;
-       /*When input vector of int ascii codes  */
-       GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&Row_Num,&Col_Num,&Stack_Pos);
-       len = Row_Num * Col_Num ;
-
-       if (len != 0)
-       {
-               int x = 0;
-               int one = 1;
-               int *Input_IntMatrix = NULL;
-               char *Output_StringMatrix = NULL;
-
-               Input_IntMatrix = istk(Stack_Pos);
-
-               outIndex = 0 ;
-               CreateVar(Rhs+1,STRING_DATATYPE,&len,&one,&outIndex);
-               Output_StringMatrix = cstk(outIndex);
-               for (x = 0; x < len; x++) 
-               {
-                       if ( FirstWarning ) 
-                       {
-                               if ( (Input_IntMatrix[x] < ASCII_MIN) || (Input_IntMatrix[x] > ASCII_MAX) )
-                               {
-                                       if (getWarningMode())
-                                       {
-                                               sciprint(_("WARNING : \n"));
-                                               sciprint(_("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),fname,1,ASCII_MIN,ASCII_MAX);
-                                       }
-                                       FirstWarning = FALSE;
-                               }
-                       }
-
-                       if (isascii(Input_IntMatrix[x]))
-                       {
-                               Output_StringMatrix[x] = (char)toascii(Input_IntMatrix[x]);
-                       }
-                       else
-                       {
-                               Output_StringMatrix[x] = (char)Input_IntMatrix[x];
-                       }
-               }
-               Output_StringMatrix[len] = '\0';
-       }
-       else
-       {
-               #define EMPTY_STR ""
-               int one    = 1 ;
-               int lenStr   = (int)strlen(EMPTY_STR);
-               outIndex = 0 ;
-               
-               CreateVar(Rhs+1,STRING_DATATYPE,&lenStr,&one,&outIndex);
-               strcpy(cstk(outIndex),EMPTY_STR);
-       }
-       
-       LhsVar(1) = Rhs+1 ;
-       C2F(putlhsvar)();
-       return 0;
-}
-
-/*--------------------------------------------------------------------------*/
-static int asciiIntMatrix(char *fname)
-{
-       int Row_Num = 0,Col_Num = 0;
-       int outIndex = 0 ;
-       int len = 0;
-       
-       SciIntMat M;
-       
-       GetRhsVar(1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&Row_Num,&Col_Num,&M);
-       len = Row_Num * Col_Num ;
-       
-       if (len != 0)
-       {
-               int one        = 1;
-               int ichar      = I_UCHAR;
-               static int inc = 1;
-               
-               char *Output_StringMatrix = NULL;
-               
-               CreateVar(Rhs+1,STRING_DATATYPE,&len,&one,&outIndex);
-               Output_StringMatrix = cstk(outIndex);
-               
-               /* from intxx to char */
-               C2F(tpconv)(&M.it,&ichar,&len, M.D, &inc, Output_StringMatrix, &inc);
-               Output_StringMatrix[len] = '\0';
-       }
-       else
-       {
-               #define EMPTY_STR ""
-               int one    = 1 ;
-               int lenStr = (int)strlen(EMPTY_STR);
-               
-               CreateVar(Rhs+1,STRING_DATATYPE,&lenStr,&one,&outIndex);
-               strcpy(cstk(outIndex),EMPTY_STR);
-       }
-       
-       LhsVar(1) = Rhs+1 ;
-       C2F(putlhsvar)();
-       return 0;
-}
-
-/*--------------------------------------------------------------------------*/
-static int asciiOthers(char *fname)
-{
-       Scierror(999,_("%s: Wrong type for argument #%d: Matrix of strings or Integer matrix expected.\n"),fname,1);
-       return 0;
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp b/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp
new file mode 100644 (file)
index 0000000..3900b7d
--- /dev/null
@@ -0,0 +1,430 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) INRIA - Cong WU
+*  Copyright (C) 2010 - DIGITEO - Antoine ELIAS
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * 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 : This function convert Scilab string to a vector of ascii code  */
+/*        or vector of ascii code to Scilab strings.                     */
+/*        If  txt  is a matrix of string,  ascii(txt)  is equivalent to  */  
+/*          ascii(strcat(txt))                                           */
+/*-----------------------------------------------------------------------*/
+
+#include "string_gw.hxx"
+extern "C"
+{
+#include <ctype.h>
+#include "MALLOC.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+}
+
+//#include "sci_warning.h"
+
+/*----------------------------------------------------------------------------*/
+String* DoubleToString(Double* _pdbl);
+String* IntToString(Int* _pi);
+Double* StringToDouble(String* _pst);
+/*----------------------------------------------------------------------------*/
+Function::ReturnValue sci_ascii(typed_list &in, int _iRetCount, typed_list &out)
+{
+    if(in.size() != 1)
+    {
+        ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d expected.\n"), L"ascii", 1);
+        return Function::Error;
+    }
+
+    InternalType* pOut;
+    switch(in[0]->getType())
+    {
+    case InternalType::RealDouble : 
+        {
+            pOut = DoubleToString(in[0]->getAsDouble());
+            break;
+        }
+    case InternalType::RealString : 
+        {
+            pOut = StringToDouble(in[0]->getAsString());
+            break;
+        }
+    case InternalType::RealInt : 
+        {
+            pOut = IntToString(in[0]->getAsInt());
+            break;
+        }
+    default :
+        ScierrorW(999, _W("%ls: Wrong type for argument #%d: Matrix of strings or Integer matrix expected.\n"), L"ascii", 1);
+        return Function::Error;
+    }
+
+    out.push_back(pOut);
+    return Function::OK;
+    
+//     CheckRhs(1,1);
+//     CheckLhs(0,1);
+//
+//     switch ( GetType(1)) 
+//     {
+//             case sci_strings:
+//                     asciiStrings(fname);
+//             break;
+//
+//             case sci_matrix :
+//                     asciiMatrix(fname);
+//             break;
+//             
+//             case sci_ints :
+//                     asciiIntMatrix(fname);
+//             break;
+//             
+//             default:
+//                     asciiOthers(fname);
+//             break;
+//  }
+//  return 0;
+//}
+///*--------------------------------------------------------------------------*/
+//static int asciiStrings(char *fname)
+//{
+//     /* interface written with stack3 */
+//     /* 3 phases :
+//              1] get data from stack 
+//                     conversion scilab code to ascii and strings (char **)
+//              2] algo. conversion ascii to values
+//              3] put results on stack
+//     */
+//
+//     /* interface written with stack1*/
+//     /* it works immediately on stack (read and write)
+//     conversion scilab code to ascii values 
+//     */
+//
+//     /* Benchmark 
+//     str_test_mat =  ["abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz", ..
+//     "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"; ..
+//     "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz", ..
+//     "abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"];
+//
+//     tic();
+//     for i=1:10000000
+//     ascii(["abscefghijklmnopqrstuvxyz","abscefghijklmnopqrstuvxyz"]);
+//     end
+//     duree = toc();
+//
+//     printf("\nDUREE 1 = %d seconds\n\n",duree);
+//     */
+//
+//     /* on windows C2D 6600 2400 mhz */
+//     /* scilab 4.1.2 : 40 s */
+//     /* scilab with stack3 interface : 75 s*/
+//     /* scilab with stack1 interface : 41 s */
+//
+///*
+//     char **Input_StringMatrix = NULL;
+//     int x = 0,y = 0,Row_Num = 0,Col_Num = 0;
+//
+//     int Length_Output_Matrix = 0;
+//     double *Output_IntMatrix = NULL;
+//     int nbOutput_IntMatrix = 0;
+//     int numRow = 1;
+//
+//     GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_Num,&Col_Num,&Input_StringMatrix);
+//
+//     Length_Output_Matrix = 0;
+//     for (x = 0;x < Row_Num*Col_Num;x++) Length_Output_Matrix = Length_Output_Matrix + (int)strlen(Input_StringMatrix[x]);
+//
+//     if (Length_Output_Matrix !=0) 
+//     {
+//             Output_IntMatrix = (double*)MALLOC(sizeof(double)*(Length_Output_Matrix));
+//     }
+//     else Output_IntMatrix = (double*)MALLOC(sizeof(double));
+//
+//     if (Output_IntMatrix == NULL)
+//     {
+//             freeArrayOfString(Input_StringMatrix,Row_Num*Col_Num);
+//             Scierror(999,_("%s: Memory allocation error.\n"),fname);
+//             return 0;
+//     }
+//
+//     for (x = 0; x < Row_Num*Col_Num; x++) 
+//     {
+//             for (y = 0;y < (int)strlen(Input_StringMatrix[x]); y++)
+//             {
+//                     Output_IntMatrix[nbOutput_IntMatrix]=Input_StringMatrix[x][y];
+//                     nbOutput_IntMatrix++;
+//             }
+//     }
+//
+//     freeArrayOfString(Input_StringMatrix,Row_Num*Col_Num);
+//
+//     
+//     CreateVarFromPtr(Rhs + 1,MATRIX_OF_DOUBLE_DATATYPE,&numRow,&nbOutput_IntMatrix,&Output_IntMatrix);
+//
+//     LhsVar(1) = Rhs + 1 ;
+//     C2F(putlhsvar)();
+//     if (Output_IntMatrix) { FREE(Output_IntMatrix); Output_IntMatrix=NULL;}
+//     return 0;
+//*/
+//
+//     BOOL is_a_reference_on_stack = FALSE; /* variable is a reference on stack */
+//     int i = 0, j = 0;
+//     int nbr_characters  = 0;
+//     int  l = 0, il = 0, lr = 0;
+//     int ilr = 0;
+//
+//     il = iadr( C2F(vstk).lstk[Top - 1] );
+//
+//     ilr = il;
+//     if (*istk(il) < 0) 
+//     {
+//             il = iadr(*istk(il+1));
+//     }
+//     /* check if parameter is a reference */
+//     is_a_reference_on_stack = (il != ilr);
+//
+//     /* find number of characters */
+//     nbr_characters = *istk(il + 4 + *istk(il + 1) * *istk(il + 2)) - 1;
+//
+//     l = il + 5 + *istk(il+1) * *istk(il+2);
+//
+//     if (is_a_reference_on_stack) 
+//     {
+//             /* it is a reference on stack : txt = 'Scilab' ; ascii(txt) */
+//             j = ilr + 4;
+//             Err = j / 2 + 1 + nbr_characters - C2F(vstk).lstk[Bot - 1];
+//             if (Err > 0) 
+//             {
+//                     /* stacksize exceeded */
+//                     SciError(17);
+//                     return 0;
+//             }
+//     } 
+//     else 
+//     {
+//             /* it is not a reference on stack  ascii('Scilab') */
+//             int one = 1;
+//             int lw = l + nbr_characters;
+//
+//             j = lw + nbr_characters;
+//             Err = j / 2 + 1 - C2F(vstk).lstk[Bot - 1];
+//             if (Err > 0) 
+//             {
+//                     /* stacksize exceeded */
+//                     SciError(17);
+//                     return 0;
+//             }
+//             C2F(icopy)(&nbr_characters, istk(l), &one, istk(l + nbr_characters), &one);
+//             l = lw;
+//     }
+//
+//     /* create output int matrix , see C2F(crematvar) stack1.c */
+//     *istk(ilr) = sci_matrix;
+//     *istk(ilr+1) = 1;
+//     *istk(ilr+2) = nbr_characters;
+//     *istk(ilr+3) = 0;
+//
+//     j = ilr + 4;
+//     lr = j / 2 + 1;
+//
+//     /* put each value on stack */
+//     for (i = 0; i < nbr_characters; i++) 
+//     {
+//             int scilab_code = *istk(l + i);
+//             *stk(lr + i) = convertScilabCodeToAsciiCode(scilab_code);
+//     }
+//     /* update Top of stack */
+//     C2F(vstk).lstk[Top] = lr + nbr_characters;
+//
+//     return 0;
+//     
+//}
+///*--------------------------------------------------------------------------*/
+//static int asciiMatrix(char *fname)
+//{
+//     int Row_Num = 0,Col_Num = 0,Stack_Pos = 0;
+//     int outIndex = 0 ;
+//     int len = 0;
+//     BOOL FirstWarning = TRUE;
+//     /*When input vector of int ascii codes  */
+//     GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&Row_Num,&Col_Num,&Stack_Pos);
+//     len = Row_Num * Col_Num ;
+//
+//     if (len != 0)
+//     {
+//             int x = 0;
+//             int one = 1;
+//             int *Input_IntMatrix = NULL;
+//             char *Output_StringMatrix = NULL;
+//
+//             Input_IntMatrix = istk(Stack_Pos);
+//
+//             outIndex = 0 ;
+//             CreateVar(Rhs+1,STRING_DATATYPE,&len,&one,&outIndex);
+//             Output_StringMatrix = cstk(outIndex);
+//             for (x = 0; x < len; x++) 
+//             {
+//                     if ( FirstWarning ) 
+//                     {
+//                             if ( (Input_IntMatrix[x] < ASCII_MIN) || (Input_IntMatrix[x] > ASCII_MAX) )
+//                             {
+//                                     if (getWarningMode())
+//                                     {
+//                                             sciprint(_("WARNING : \n"));
+//                                             sciprint(_("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"),fname,1,ASCII_MIN,ASCII_MAX);
+//                                     }
+//                                     FirstWarning = FALSE;
+//                             }
+//                     }
+//
+//                     if (isascii(Input_IntMatrix[x]))
+//                     {
+//                             Output_StringMatrix[x] = (char)toascii(Input_IntMatrix[x]);
+//                     }
+//                     else
+//                     {
+//                             Output_StringMatrix[x] = (char)Input_IntMatrix[x];
+//                     }
+//             }
+//             Output_StringMatrix[len] = '\0';
+//     }
+//     else
+//     {
+//             #define EMPTY_STR ""
+//             int one    = 1 ;
+//             int lenStr   = (int)strlen(EMPTY_STR);
+//             outIndex = 0 ;
+//             
+//             CreateVar(Rhs+1,STRING_DATATYPE,&lenStr,&one,&outIndex);
+//             strcpy(cstk(outIndex),EMPTY_STR);
+//     }
+//     
+//     LhsVar(1) = Rhs+1 ;
+//     C2F(putlhsvar)();
+//     return 0;
+//}
+//
+///*--------------------------------------------------------------------------*/
+//static int asciiIntMatrix(char *fname)
+//{
+//     int Row_Num = 0,Col_Num = 0;
+//     int outIndex = 0 ;
+//     int len = 0;
+//     
+//     SciIntMat M;
+//     
+//     GetRhsVar(1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&Row_Num,&Col_Num,&M);
+//     len = Row_Num * Col_Num ;
+//     
+//     if (len != 0)
+//     {
+//             int one        = 1;
+//             int ichar      = I_UCHAR;
+//             static int inc = 1;
+//             
+//             char *Output_StringMatrix = NULL;
+//             
+//             CreateVar(Rhs+1,STRING_DATATYPE,&len,&one,&outIndex);
+//             Output_StringMatrix = cstk(outIndex);
+//             
+//             /* from intxx to char */
+//             C2F(tpconv)(&M.it,&ichar,&len, M.D, &inc, Output_StringMatrix, &inc);
+//             Output_StringMatrix[len] = '\0';
+//     }
+//     else
+//     {
+//             #define EMPTY_STR ""
+//             int one    = 1 ;
+//             int lenStr = (int)strlen(EMPTY_STR);
+//             
+//             CreateVar(Rhs+1,STRING_DATATYPE,&lenStr,&one,&outIndex);
+//             strcpy(cstk(outIndex),EMPTY_STR);
+//     }
+//     
+//     LhsVar(1) = Rhs+1 ;
+//     C2F(putlhsvar)();
+//     return 0;
+//}
+//
+///*--------------------------------------------------------------------------*/
+//static int asciiOthers(char *fname)
+//{
+//     Scierror(999,_("%s: Wrong type for argument #%d: Matrix of strings or Integer matrix expected.\n"),fname,1);
+//     return 0;
+}
+/*--------------------------------------------------------------------------*/
+String* DoubleToString(Double* _pdbl)
+{
+    String* pOut = NULL;
+    char* pst = (char*)MALLOC(sizeof(char) * (_pdbl->size_get() + 1));
+    memset(pst, 0x00, _pdbl->size_get() + 1);
+    double* pdbl = _pdbl->real_get();
+
+    bool bWarning = false;
+    for(int i = 0 ; i < _pdbl->size_get() ; i++)
+    {
+        if(bWarning == false && pdbl[i] > 255)
+        {
+            sciprintW(_W("WARNING : \n"));
+            sciprintW(_W("%ls: Wrong value for input argument #%d: Must be between %d and %d.\n"), L"ascii", 1, 0, 255);
+            bWarning = true;
+        }
+        pst[i] = (char)toascii((int)pdbl[i]);
+    }
+
+    wchar_t* pwst = to_wide_string(pst);
+    pOut = new String(1, 1);
+    pOut->string_set(0, 0, pwst);
+    return pOut;
+}
+/*--------------------------------------------------------------------------*/
+String* IntToString(Int* _pi)
+{
+    String* pOut = NULL;
+
+    return pOut;
+}
+/*--------------------------------------------------------------------------*/
+Double* StringToDouble(String* _pst)
+{
+    Double* pOut = NULL;
+    /*compute total length*/
+    for(int i = 0 ; i < _pst->size_get() ; i++)
+    {
+        char* pst = wide_string_to_UTF8(_pst->string_get(i));
+        if(pOut == NULL)
+        {
+            pOut = new Double(1, (int)strlen(pst));
+            int iLen = (int)strlen(pst);
+            double* pD = pOut->real_get();
+            for(int j = 0 ; j < iLen ; j++)
+            {
+                pD[j] = pst[j];
+            }
+        }
+        else
+        {
+            int iLen = (int)strlen(pst);
+            Double *pIn = new Double(1, iLen);
+            double* pD = pIn->real_get();
+            for(int j = 0 ; j < iLen ; j++)
+            {
+                pD[j] = pst[j];
+            }
+
+            int iOldCols = pOut->cols_get();
+            pOut->resize(1, iOldCols + iLen);
+            pOut->append(0, iOldCols, pIn);
+            delete pIn;
+        }
+    }
+    return pOut;
+}
+/*--------------------------------------------------------------------------*/
index 99cb18b..6ea6fb6 100644 (file)
@@ -28,5 +28,6 @@ bool StringModule::Load()
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"strindex", &sci_strindex, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"strsubst", &sci_strsubst, MODULE_NAME));
     symbol::Context::getInstance()->AddFunction(Function::createFunction(L"strsplit", &sci_strsplit, MODULE_NAME));
+    symbol::Context::getInstance()->AddFunction(Function::createFunction(L"ascii", &sci_ascii, MODULE_NAME));
     return true;
 }
index 48ce935..2a59135 100644 (file)
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
+                               RelativePath=".\sci_ascii.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\sci_grep.cpp"
                                >
                        </File>
index 15f0e14..dd34202 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath="..\..\sci_gateway\c\sci_ascii.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\c\sci_code2str.c"
                                >
                        </File>