med_utils.h

Aller à la documentation de ce fichier.
00001 /* -*- mode:C; coding:utf-8 -*- */
00002 /*  This file is part of MED.
00003  *
00004  *  COPYRIGHT (C) 1999 - 2012  EDF R&D, CEA/DEN
00005  *  MED is free software: you can redistribute it and/or modify
00006  *  it under the terms of the GNU Lesser General Public License as published by
00007  *  the Free Software Foundation, either version 3 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  MED is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public License
00016  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 
00020 # ifndef __UTILITES_H__
00021 # define __UTILITES_H__
00022 
00023 #include <stdlib.h>
00024 #include <med_exit_if.h>
00025 #include <med_err.h>
00026 
00027 /* pour indiquer le statut des arguments des fonctions. */
00028 
00029 #ifdef _IN
00030 #error _IN already defined
00031 #endif
00032 #define _IN
00033 
00034 #ifdef _OUT
00035 #error _OUT already defined
00036 #endif
00037 #define _OUT
00038 
00039 #ifdef _INOUT
00040 #error _INOUT already defined
00041 #endif
00042 #define _INOUT
00043 
00044 #ifdef _UNUSED
00045 #error _UNUSED already defined
00046 #endif
00047 #define _UNUSED
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 /* --- Pour afficher le nom du fichier source courant et le numero de la ligne courante --- */
00056 /* --- sur la stderr.                                                                   --- */
00057 
00058 # define ICI                    {\
00059                                         fflush(stdout);\
00060                                         fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
00061                                         fflush(stderr) ;\
00062                                 }
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 /* --- Pour afficher la date et l'heure de la compilation du fichier source courant,    --- */
00071 /* --- sur la stdout.                                                                   --- */
00072 
00073 # ifdef INFOS_COMPILATION
00074 # error INFOS_COMPILATION already defined
00075 # endif
00076 # define INFOS_COMPILATION      {\
00077                                         fflush(stderr);\
00078                                         fprintf(stdout, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
00079                                         fprintf(stdout,"Compilation le %s" , __DATE__);\
00080                                         fprintf(stdout," a %s" , __TIME__ );\
00081                                         fprintf(stdout,"\n\n\n" );\
00082                                         fflush(stdout) ;\
00083                                 }
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 /* --- Pour attendre "secondes" secondes et afficher un message sur la stderr indiquant --- */
00092 /* --- cette attente volontaire.                                                        --- */
00093 
00094 # ifdef ATTENTE
00095 # error ATTENTE already defined
00096 # endif
00097 # define ATTENTE(secondes)      {\
00098                                         ICI ;\
00099                                         fprintf( stderr, "ATTENTE de %d secondes" , secondes);\
00100                                         fflush(stderr) ;\
00101                                         sleep(secondes) ;\
00102                                         fprintf( stderr, "\n" );\
00103                                         fflush(stderr) ;\
00104                                 }
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 /* ----------    Les macros suivantes ne doivent pas deja exister !              ---------- */
00113 
00114 # ifdef EXECUTION
00115 # error EXECUTION already defined
00116 # endif
00117 # ifdef INTERRUPTION
00118 # error INTERRUPTION already defined
00119 # endif
00120 # ifdef ISCRUTE
00121 # error ISCRUTE already defined
00122 # endif
00123 # ifdef RSCRUTE
00124 # error RSCRUTE already defined
00125 # endif
00126 # ifdef SSCRUTE
00127 # error SSCRUTE already defined
00128 # endif
00129 # ifdef CSCRUTE
00130 # error CSCRUTE already defined
00131 # endif
00132 # ifdef XSCRUTE
00133 # error XSCRUTE already defined
00134 # endif
00135 # ifdef MESSAGE
00136 # error MESSAGE already defined
00137 # endif
00138 
00139 
00140 
00141 /* D馩nition du format ?tiliser pour afficher un med_int */
00142 # define IFORMAT_int "%d"
00143 # define IFORMAT_long "%ld"
00144 # define IFORMAT IFORMAT_int
00145 
00146 # define MED_IFORMAT_int "d"
00147 # define MED_IFORMAT_long "ld"
00148 # define MED_IFORMAT MED_IFORMAT_int
00149 
00150 #define MED_EXP2_(msg1,msg2) msg1 msg2
00151 #define MED_ERR_(rt,r1,r2,r3) { rt = r1 r2; MESSAGE(MED_EXP2_(r1 ## _MSG,r2 ## _MSG)); MESSAGE(r3); }
00152 
00153 
00154 #if ! defined(MESGERR)
00155 #error "Explicit error messages must be either activated or deactivated, hence MESGERR macro must be defined."
00156 #error "Verify that you include med_utils.h after med_config.h, thanks."
00157 #endif
00158 
00159 # if MESGERR == 1 || defined(MED_MESGERR_FOR_TOOLS)
00160 
00161 
00162 /* --- Pour tracer sur la stderr l'execution d"une instruction.                         --- */
00163 
00164 # define EXECUTION(instruction) {\
00165                                         ICI ;\
00166                                         fprintf( stderr,"INSTRUCTION %s" , #instruction ) ;\
00167                                         fflush(stderr);\
00168                                         instruction ;\
00169                                         fflush(stdout);\
00170                                         fprintf( stderr," FRANCHIE\n" ) ;\
00171                                         fflush(stderr);\
00172                                 }
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 /* --- Pour afficher un message d'interruption volontaire et retourner le code retour   --- */
00181 /* --- "code"                                                                           --- */
00182 
00183 # define INTERRUPTION(code)     {\
00184                                         ICI ;\
00185                                         fprintf( stderr," INTERRUPTION code = %d",code) ;\
00186                                         fprintf(stderr,"\n") ;\
00187                                         exit(code) ;\
00188                                 }
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 /* --- Pour conditionner la poursuite du traitement par la validite de la condition     --- */
00197 /* --- "condition".                                                                     --- */
00198 
00199 # ifndef ASSERT
00200 # define ASSERT(condition)      if( !(condition) ){\
00201                                         ICI ;\
00202                                         fprintf(stderr,"condition %s VIOLEE\n",#condition);\
00203                                         INTERRUPTION(17);\
00204                                 }
00205 # endif         /* # ifndef ASSERT */
00206 
00207 
00208 /* --- Pour conditionner la poursuite du traitement au fait qu'une chaine ne finie pas par un blanc --- */
00209 /* --- "nofinalblank".                                                                              --- */
00210 # ifndef NOFINALBLANK
00211 # define NOFINALBLANK(chaine,label) if (chaine) if (strlen(chaine)) if( ( chaine[strlen(chaine)-1] == ' ' ) ){ \
00212                                         ICI ;\
00213                                         fprintf(stderr,"La chaine |%s| ne doit pas finir par un caract貥 blanc.\n",chaine);\
00214                                         goto label;                     \
00215                                 }
00216 # endif         /* # ifndef NOFINALBLANK */
00217 
00218 
00219 
00220 
00221 
00222 
00223 /* --- Pour afficher sur la stderr la valeur d'une variable precedee de son nom.        --- */
00224 
00225 # define ISCRUTE(entier)        ISCRUTE_int(entier)
00226 
00227 # define ISCRUTE_int(entier)    {\
00228                                         ICI ;\
00229                                         fprintf(stderr,"%s = %d\n",#entier,entier) ;\
00230                                         fflush(stderr) ;\
00231                                 }
00232 # define ISCRUTE_long(entier)   {\
00233                                         ICI ;\
00234                                         fprintf(stderr,"%s = %ld\n",#entier,entier) ;\
00235                                         fflush(stderr) ;\
00236                                 }
00237 # define ISCRUTE_llong(entier)  {\
00238                                         ICI ;\
00239                                         fprintf(stderr,"%s = %lld\n",#entier,entier) ;\
00240                                         fflush(stderr) ;\
00241                                 }
00242 # define ISCRUTE_size(entier)   {\
00243                                         ICI ;\
00244                                         fprintf(stderr,"%s = %llu\n",#entier,entier) ;\
00245                                         fflush(stderr) ;\
00246                                 }
00247 # define ISCRUTE_id(entier) ISCRUTE_int(entier)
00248 # define RSCRUTE(reel)          {\
00249                                         ICI ;\
00250                                         fprintf(stderr,"%s = %f\n",#reel,reel) ;\
00251                                         fflush(stderr) ;\
00252                                 }
00253 # define XSCRUTE(pointeur)              {\
00254                                         ICI ;\
00255                                         fprintf(stderr,"%s = %p\n",#pointeur,pointeur) ;\
00256                                         fflush(stderr) ;\
00257                                 }
00258 # define CSCRUTE(car)           {\
00259                                         ICI ;\
00260                                         fprintf(stderr,"%s = %c\n",#car,car) ;\
00261                                         fflush(stderr) ;\
00262                                 }
00263 # define SSCRUTE(chaine)        {\
00264                                         ICI ;\
00265                                         fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
00266                                         fflush(stderr) ;\
00267                                 }
00268 # define MESSAGE(chaine)        {\
00269                                         ICI ;\
00270                                         fprintf(stderr,"%s\n",chaine) ;\
00271                                         fflush(stderr) ;\
00272                                 }
00273 # define FIN(nom)               {\
00274                                         ICI ;\
00275                                         fprintf( stderr , "} FIN %s\n\n\n" , nom ) ;\
00276                                         fflush(stderr) ;\
00277                                 }
00278 # define DEBUT(nom)             {\
00279                                         fprintf( stderr , "\n\n\n") ;\
00280                                         ICI ;\
00281                                         fprintf( stderr , "{ DEBUT %s\n" , nom ) ;\
00282                                         fflush(stderr) ;\
00283                                 }
00284 
00285 
00286 # else          /* # if MESGERR != 1*/
00287 
00288 
00289 
00290 # define EXECUTION(instruction) instruction
00291 # define INTERRUPTION(code)
00292 
00293 # ifndef ASSERT
00294 # define ASSERT(condition)
00295 # endif
00296 
00297 # define NOFINALBLANK(chaine,label)
00298 
00299 # define ISCRUTE(entier)
00300 # define ISCRUTE_int(entier)
00301 # define ISCRUTE_long(entier)
00302 # define ISCRUTE_llong(entier)
00303 # define ISCRUTE_size(entier)
00304 # define ISCRUTE_id(entier)
00305 # define XSCRUTE(pointeur)
00306 # define RSCRUTE(reel)
00307 # define CSCRUTE(car)
00308 # define SSCRUTE(chaine)
00309 # define MESSAGE(chaine)
00310 # define DEBUT(nom)
00311 # define FIN(nom)
00312 
00313 # endif         /* # if MESGERR */
00314 
00315 /* Ces macros ne doivent être utilisées que dans les outils ou les tests.
00316    Elles ne doivent pas être utilsées dans la bibliothèque (pour respecter l'option --disable-mesgerr).
00317 */
00318 
00319 # ifdef WITH_EXCEPTIONS
00320 #   ifdef __cplusplus
00321 #    define EXIT_IF(expression,message,arg) {\
00322            if ( ( expression ) != 0)                                            \
00323              throw MEDerreur(__FILE__,__LINE__,message,arg); }
00324 #   else
00325 #     error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
00326 #   endif
00327 # else
00328 # define EXIT_IF(expression,message,arg) { exit_if(__FILE__,__LINE__,expression,message,arg); }
00329 # endif
00330 
00331 
00332 # ifdef WITH_EXCEPTIONS
00333 #   ifdef __cplusplus
00334 #    define MED_ERR_EXIT_IF(expression,r1,r2,arg) {\
00335            if ( ( expression ) != 0)                                            \
00336              throw MEDerreur(__FILE__,__LINE__,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
00337 #   else
00338 #     error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
00339 #   endif
00340 # else
00341 # define MED_ERR_EXIT_IF(expression,r1,r2,arg) { exit_if(__FILE__,__LINE__,expression,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
00342 # endif
00343 
00344 
00345 # endif         /* # ifndef __UTILITES_H__ */

Généré le Mon Apr 23 11:30:26 2012 pour MED fichier par  doxygen 1.6.1