_MED23v30stringConvert.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 #include <string.h>
00023 
00024 /*
00025  *  Chaine C MED2.3 -> Chaine C MED3.0
00026  */
00027 
00028 med_err _MED23v30stringConvert(char *chaine30, med_int substrsize30,
00029                                char *chaine23, med_int substrsize23,
00030                                med_int nsubstr )
00031 {
00032   int       i,j;
00033   med_int  _substrsize23 = substrsize23;
00034   med_int  _nsubstr      = 0;
00035   med_int  _realnsubstr  = 0;
00036   int      _lenchaine23  = 0;
00037 
00038   if ( substrsize30 < substrsize23 ) return -1;
00039 
00040   _lenchaine23 = strlen(chaine23);
00041   _realnsubstr = _lenchaine23/substrsize23;
00042 
00043   if ( ( _realnsubstr < nsubstr) && _lenchaine23 ) {
00044 /*     MESSAGE("Be careful, size of string chaine23 should a multiple of substrsize23"); */
00045 /*     SSCRUTE(chaine23); */
00046 /*     ISCRUTE(_lenchaine23); */
00047 /*     ISCRUTE(substrsize23); */
00048 /*     ISCRUTE(nsubstr); */
00049 /*     ISCRUTE(_realnsubstr); */
00050     _nsubstr=_realnsubstr+1;
00051   }
00052   if (_realnsubstr == nsubstr ) _nsubstr=nsubstr;
00053 /*     SSCRUTE(chaine23); */
00054 /*     ISCRUTE(_lenchaine23); */
00055 /*     ISCRUTE(substrsize23); */
00056 /*     ISCRUTE(nsubstr); */
00057 /*     ISCRUTE(_nsubstr); */
00058 /*     ISCRUTE(_realnsubstr); */
00059 
00060   for (i=0;i<_nsubstr;i++) {
00061     strncpy(chaine30+i*substrsize30,
00062             chaine23+i*substrsize23,
00063             substrsize23);
00064 
00065     if ( (i == (_nsubstr-1)       ) &&
00066          (_realnsubstr != nsubstr ) ) _substrsize23=_lenchaine23-_realnsubstr*substrsize23;
00067 
00068     for (j=_substrsize23;j<substrsize30;j++) {
00069       *(chaine30+i*substrsize30 + j)=' ';
00070     }
00071   }
00072   *(chaine30+_nsubstr*substrsize30) = '\0';
00073 /*   SSCRUTE(chaine30); */
00074 /*   ISCRUTE(strlen(chaine30)); */
00075 
00076   return 0;
00077 }

Généré le Mon May 16 17:10:22 2011 pour MED fichier par  doxygen 1.6.1