Salome HOME
update with the version in the OCC branch OCC_development_generic_2006.
[modules/med.git] / src / MEDWrapper / V2_1 / Core / MED2cstring.cxx
1 /*************************************************************************
2 * COPYRIGHT (C) 1999 - 2002  EDF R&D
3 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
4 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
5 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
6 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
7 *  
8 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
9 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
11 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
12 *
13 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
14 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
15 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
16 *
17 *************************************************************************/
18
19 #include <stdlib.h>
20 #include "med_misc.hxx"
21
22 /*
23  * - Nom de la fonction _MED2cstring
24  * - Description : convertit une chaine de caracteres FORTRAN en 
25  *                 nouvelle chaine de caracteres C
26  * - Parametres :
27  *     - chaine (IN)   : la chaine FORTRAN
28  *     - longueur (IN) : longueur de la chaine
29  * - Resultat : la nouvelle chaine C en cas de succes, NULL sinon
30  */
31
32 namespace med_2_1{
33
34 char *
35 _MED2cstring(char *chaine, int longueur)
36 {
37   char *nouvelle;
38   char *temoin;
39   int long_reelle = longueur;
40   int i;
41
42   if ( longueur < 0 ) return NULL;
43
44   temoin = chaine+longueur-1;
45   while (*temoin == ' ' && (temoin != chaine) )
46     {
47       temoin --;
48       long_reelle--;
49     }
50   if ( *temoin == ' ') long_reelle = 0;
51       
52   if ((nouvelle = (char *) malloc(sizeof(char)*(long_reelle+1))) == NULL)
53     return NULL;
54
55   for (i=0;i<long_reelle+1;i++)
56     *(nouvelle+i) = *(chaine+i);
57   *(nouvelle+long_reelle) = '\0';
58
59   return nouvelle;
60 }
61
62 }