StringMatrix.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------------------------*/
00002 /* COPYRIGHT INRIA 2006                                                                      */
00003 /* File    : StringMatrix.c                                                                  */
00004 /* Authors : Jean-Baptiste Silvy 2006-xxxx                                                   */
00005 /* Desc.   : Allocation and deletion and modifications of matrices of strings.               */
00006 /*           The matrix is stored by colmuns like in Scilab                                  */
00007 /*-------------------------------------------------------------------------------------------*/
00008 
00009 #include <string.h>
00010 #include "StringMatrix.h"
00011 #include "MALLOC.h"
00012 #include <stdlib.h>
00013 
00014 /*-------------------------------------------------------------------------------------------*/
00015 StringMatrix * newFullStringMatrix( char ** textMat, int nbRow, int nbCol )
00016 {
00017   int i ;
00018   /* create the matrix */
00019   StringMatrix * newMat = newMatrix( nbRow, nbCol ) ;
00020 
00021   /* copy each element */
00022   for ( i = 0 ; i < nbRow * nbCol ; i++ )
00023   {
00024     /* +1 for the /0 last character */
00025     newMat->data[i] = CALLOC( strlen(textMat[i]) + 1, sizeof(char) ) ;
00026     strcpy( newMat->data[i], textMat[i] ) ;
00027   }
00028 
00029   return newMat ;
00030 }
00031 /*-------------------------------------------------------------------------------------------*/
00032 StringMatrix * copyStringMatrix( const StringMatrix * copyMat )
00033 {
00034   return newFullStringMatrix( (char **) copyMat->data, copyMat->nbCol, copyMat->nbRow ) ;
00035 }
00036 /*-------------------------------------------------------------------------------------------*/
00037 char * getStrMatElement( const StringMatrix * mat, int row, int col )
00038 {
00039   return (char *) getMatElement( mat, row, col ) ;
00040 }
00041 /*-------------------------------------------------------------------------------------------*/
00042 char ** getStrMatData( const StringMatrix * mat )
00043 {
00044   return (char **) getMatData( mat ) ;
00045 }
00046 /*-------------------------------------------------------------------------------------------*/
00047 void copyStrMatElement( StringMatrix * mat, int row, int col, const char * copyStr )
00048 {
00049   char * changedString = (char *) mat->data[row + col * mat->nbRow] ; /* for speed */
00050   if ( changedString != NULL )
00051   {
00052     FREE( changedString ) ;
00053   }
00054   changedString = CALLOC( strlen( copyStr ) + 1, sizeof(char) ) ;
00055   strcpy( changedString, copyStr ) ;
00056   mat->data[row + col * mat->nbRow] = changedString ;
00057 }
00058 /*-------------------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:53 2007 for Scilab [trunk] by  doxygen 1.5.1