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 - 2009  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_long
00145 
00146 #define MED_EXP2_(msg1,msg2) msg1 msg2
00147 #define MED_ERR_(rt,r1,r2,r3) { rt = r1 r2; MESSAGE(MED_EXP2_(r1 ## _MSG,r2 ## _MSG)); MESSAGE(r3); }
00148 
00149 
00150 #if ! defined(MESGERR)
00151 #error "Explicit error messages must be either activated or deactivated, hence MESGERR macro must be defined."
00152 #error "Verify that you include med_utils.h after med_config.h, thanks."
00153 #endif
00154 
00155 # if MESGERR == 1
00156 
00157 
00158 /* --- Pour tracer sur la stderr l'execution d"une instruction.                         --- */
00159 
00160 # define EXECUTION(instruction) {\
00161                                         ICI ;\
00162                                         fprintf( stderr,"INSTRUCTION %s" , #instruction ) ;\
00163                                         fflush(stderr);\
00164                                         instruction ;\
00165                                         fflush(stdout);\
00166                                         fprintf( stderr," FRANCHIE\n" ) ;\
00167                                         fflush(stderr);\
00168                                 }
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 /* --- Pour afficher un message d'interruption volontaire et retourner le code retour   --- */
00177 /* --- "code"                                                                           --- */
00178 
00179 # define INTERRUPTION(code)     {\
00180                                         ICI ;\
00181                                         fprintf( stderr," INTERRUPTION code = %d",code) ;\
00182                                         fprintf(stderr,"\n") ;\
00183                                         exit(code) ;\
00184                                 }
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 /* --- Pour conditionner la poursuite du traitement par la validite de la condition     --- */
00193 /* --- "condition".                                                                     --- */
00194 
00195 # ifndef ASSERT
00196 # define ASSERT(condition)      if( !(condition) ){\
00197                                         ICI ;\
00198                                         fprintf(stderr,"condition %s VIOLEE\n",#condition);\
00199                                         INTERRUPTION(17);\
00200                                 }
00201 # endif         /* # ifndef ASSERT */
00202 
00203 
00204 /* --- Pour conditionner la poursuite du traitement au fait qu'une chaine ne finie pas par un blanc --- */
00205 /* --- "nofinalblank".                                                                              --- */
00206 # ifndef NOFINALBLANK
00207 # define NOFINALBLANK(chaine,label) if (chaine) if (strlen(chaine)) if( ( chaine[strlen(chaine)-1] == ' ' ) ){ \
00208                                         ICI ;\
00209                                         fprintf(stderr,"La chaine |%s| ne doit pas finir par un caract貥 blanc.\n",chaine);\
00210                                         goto label;                     \
00211                                 }
00212 # endif         /* # ifndef NOFINALBLANK */
00213 
00214 
00215 
00216 
00217 
00218 
00219 /* --- Pour afficher sur la stderr la valeur d'une variable precedee de son nom.        --- */
00220 
00221 # define ISCRUTE(entier)        ISCRUTE_long(entier)
00222 
00223 # define ISCRUTE_int(entier)    {\
00224                                         ICI ;\
00225                                         fprintf(stderr,"%s = %d\n",#entier,entier) ;\
00226                                         fflush(stderr) ;\
00227                                 }
00228 # define ISCRUTE_long(entier)   {\
00229                                         ICI ;\
00230                                         fprintf(stderr,"%s = %ld\n",#entier,entier) ;\
00231                                         fflush(stderr) ;\
00232                                 }
00233 # define ISCRUTE_llong(entier)  {\
00234                                         ICI ;\
00235                                         fprintf(stderr,"%s = %lld\n",#entier,entier) ;\
00236                                         fflush(stderr) ;\
00237                                 }
00238 # define ISCRUTE_size(entier)   {\
00239                                         ICI ;\
00240                                         fprintf(stderr,"%s = %llu\n",#entier,entier) ;\
00241                                         fflush(stderr) ;\
00242                                 }
00243 # define ISCRUTE_id(entier) ISCRUTE_int(entier)
00244 # define RSCRUTE(reel)          {\
00245                                         ICI ;\
00246                                         fprintf(stderr,"%s = %f\n",#reel,reel) ;\
00247                                         fflush(stderr) ;\
00248                                 }
00249 # define XSCRUTE(pointeur)              {\
00250                                         ICI ;\
00251                                         fprintf(stderr,"%s = %p\n",#pointeur,pointeur) ;\
00252                                         fflush(stderr) ;\
00253                                 }
00254 # define CSCRUTE(car)           {\
00255                                         ICI ;\
00256                                         fprintf(stderr,"%s = %c\n",#car,car) ;\
00257                                         fflush(stderr) ;\
00258                                 }
00259 # define SSCRUTE(chaine)        {\
00260                                         ICI ;\
00261                                         fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
00262                                         fflush(stderr) ;\
00263                                 }
00264 # define MESSAGE(chaine)        {\
00265                                         ICI ;\
00266                                         fprintf(stderr,"%s\n",chaine) ;\
00267                                         fflush(stderr) ;\
00268                                 }
00269 # define FIN(nom)               {\
00270                                         ICI ;\
00271                                         fprintf( stderr , "} FIN %s\n\n\n" , nom ) ;\
00272                                         fflush(stderr) ;\
00273                                 }
00274 # define DEBUT(nom)             {\
00275                                         fprintf( stderr , "\n\n\n") ;\
00276                                         ICI ;\
00277                                         fprintf( stderr , "{ DEBUT %s\n" , nom ) ;\
00278                                         fflush(stderr) ;\
00279                                 }
00280 
00281 # ifdef WITH_EXCEPTIONS
00282 #   ifdef __cplusplus
00283 #    define EXIT_IF(expression,message,arg) {\
00284            if ( ( expression ) != 0)                                            \
00285              throw MEDerreur(__FILE__,__LINE__,message,arg); }
00286 #   else
00287 #     error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
00288 #   endif
00289 # else
00290 # define EXIT_IF(expression,message,arg) { exit_if(__FILE__,__LINE__,expression,message,arg); }
00291 # endif
00292 
00293 
00294 # ifdef WITH_EXCEPTIONS
00295 #   ifdef __cplusplus
00296 #    define MED_ERR_EXIT_IF(expression,r1,r2,arg) {\
00297            if ( ( expression ) != 0)                                            \
00298              throw MEDerreur(__FILE__,__LINE__,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
00299 #   else
00300 #     error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
00301 #   endif
00302 # else
00303 # define MED_ERR_EXIT_IF(expression,r1,r2,arg) { exit_if(__FILE__,__LINE__,expression,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
00304 # endif
00305 
00306 
00307 # else          /* # if MESGERR != 1*/
00308 
00309 
00310 
00311 # define EXECUTION(instruction) instruction
00312 # define INTERRUPTION(code)
00313 
00314 # ifndef ASSERT
00315 # define ASSERT(condition)
00316 # endif
00317 
00318 # define NOFINALBLANK(chaine,label)
00319 
00320 # define ISCRUTE(entier)
00321 # define ISCRUTE_int(entier)
00322 # define ISCRUTE_long(entier)
00323 # define ISCRUTE_llong(entier)
00324 # define ISCRUTE_size(entier)
00325 # define ISCRUTE_id(entier)
00326 # define XSCRUTE(pointeur)
00327 # define RSCRUTE(reel)
00328 # define CSCRUTE(car)
00329 # define SSCRUTE(chaine)
00330 # define MESSAGE(chaine)
00331 # define DEBUT(nom)
00332 # define FIN(nom)
00333 # define EXIT_IF(expression,message,arg)
00334 # define MED_ERR_EXIT_IF(expression,r1,r2,arg)
00335 
00336 # endif         /* # if MESGERR */
00337 
00338 
00339 # endif         /* # ifndef __UTILITES_H__ */

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