Salome HOME
update with the version in the OCC branch OCC_development_generic_2006.
[modules/med.git] / src / MEDWrapper / V2_1 / Core / MED1cstring.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
20 #include <stdlib.h>
21 #include "med_misc.hxx"
22
23 /*
24  * - Nom de la fonction : _MED1cstring
25  * - Description : convertit une chaine de caracteres FORTRAN
26  *                 en une nouvelle chaine de caracteres C
27  *                 dont la longueur est passee en parametre.
28  *                 Les caracteres completes sont des blancs
29  * - Parametres :
30  *     - chaine (IN)          : la chaine FORTRAN
31  *     - longueur_reelle (IN) : la longueur de la chaine FORTRAN
32  *     - longueur_fixee (IN)  : longueur de la chaine C a construire
33  * - Resultat : la nouvelle chaine C en cas de succes, NULL sinon
34  */
35
36 namespace med_2_1{
37
38 char *
39 _MED1cstring(char *chaine,int longueur_reelle,int longueur_fixee)
40 {
41   char *nouvelle;
42   int i;
43
44   if (longueur_reelle > longueur_fixee)
45     return NULL;
46
47   if ((nouvelle = (char *) malloc(sizeof(char)*(longueur_fixee+1))) == NULL)
48     return NULL;
49
50   for (i=0;i<longueur_reelle;i++)
51     *(nouvelle+i) = *(chaine+i);
52
53   for (i=longueur_reelle;i<longueur_fixee;i++)
54     *(nouvelle+i) = ' ';
55   
56   *(nouvelle+longueur_fixee) = '\0';
57
58   return nouvelle;
59 }
60
61 }