Back to index

salome-med  6.5.0
MED2cstring.cxx
Go to the documentation of this file.
00001 /*************************************************************************
00002 * COPYRIGHT (C) 1999 - 2002  EDF R&D
00003 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
00004 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
00005 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00006 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00007 *  
00008 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
00009 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
00010 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
00011 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
00012 *
00013 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
00014 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
00015 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
00016 *
00017 *************************************************************************/
00018 
00019 #include <stdlib.h>
00020 #include "med_misc.hxx"
00021 
00022 /*
00023  * - Nom de la fonction _MED2cstring
00024  * - Description : convertit une chaine de caracteres FORTRAN en 
00025  *                 nouvelle chaine de caracteres C
00026  * - Parametres :
00027  *     - chaine (IN)   : la chaine FORTRAN
00028  *     - longueur (IN) : longueur de la chaine
00029  * - Resultat : la nouvelle chaine C en cas de succes, NULL sinon
00030  */
00031 
00032 namespace med_2_1{
00033 
00034 char *
00035 _MED2cstring(char *chaine, int longueur)
00036 {
00037   char *nouvelle;
00038   char *temoin;
00039   int long_reelle = longueur;
00040   int i;
00041 
00042   if ( longueur < 0 ) return NULL;
00043 
00044   temoin = chaine+longueur-1;
00045   while (*temoin == ' ' && (temoin != chaine) )
00046     {
00047       temoin --;
00048       long_reelle--;
00049     }
00050   if ( *temoin == ' ') long_reelle = 0;
00051       
00052   if ((nouvelle = (char *) malloc(sizeof(char)*(long_reelle+1))) == NULL)
00053     return NULL;
00054 
00055   for (i=0;i<long_reelle+1;i++)
00056     *(nouvelle+i) = *(chaine+i);
00057   *(nouvelle+long_reelle) = '\0';
00058 
00059   return nouvelle;
00060 }
00061 
00062 }