2.3.6/med_utils.h

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2009  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 # ifndef __UTILITES_H__
00019 # define __UTILITES_H__
00020 
00021 #include <stdlib.h>
00022 #include <med_exit_if.h>
00023 
00024 /* pour indiquer le statut des arguments des fonctions. */
00025 
00026 #ifdef _IN
00027 #error _IN already defined
00028 #endif
00029 #define _IN
00030 
00031 #ifdef _OUT
00032 #error _OUT already defined
00033 #endif
00034 #define _OUT
00035 
00036 #ifdef _INOUT
00037 #error _INOUT already defined
00038 #endif
00039 #define _INOUT
00040 
00041 #ifdef _UNUSED
00042 #error _UNUSED already defined
00043 #endif
00044 #define _UNUSED
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 /* --- Pour afficher le nom du fichier source courant et le numero de la ligne courante --- */
00053 /* --- sur la stderr.                                                                   --- */
00054 
00055 # define ICI                    {\
00056                                         fflush(stdout);\
00057                                         fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
00058                                         fflush(stderr) ;\
00059                                 }
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 /* --- Pour afficher la date et l'heure de la compilation du fichier source courant,    --- */
00068 /* --- sur la stdout.                                                                   --- */
00069 
00070 # ifdef INFOS_COMPILATION
00071 # error INFOS_COMPILATION already defined
00072 # endif
00073 # define INFOS_COMPILATION      {\
00074                                         fflush(stderr);\
00075                                         fprintf(stdout, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
00076                                         fprintf(stdout,"Compilation le %s" , __DATE__);\
00077                                         fprintf(stdout," a %s" , __TIME__ );\
00078                                         fprintf(stdout,"\n\n\n" );\
00079                                         fflush(stdout) ;\
00080                                 }
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 /* --- Pour attendre "secondes" secondes et afficher un message sur la stderr indiquant --- */
00089 /* --- cette attente volontaire.                                                        --- */
00090 
00091 # ifdef ATTENTE
00092 # error ATTENTE already defined
00093 # endif
00094 # define ATTENTE(secondes)      {\
00095                                         ICI ;\
00096                                         fprintf( stderr, "ATTENTE de %d secondes" , secondes);\
00097                                         fflush(stderr) ;\
00098                                         sleep(secondes) ;\
00099                                         fprintf( stderr, "\n" );\
00100                                         fflush(stderr) ;\
00101                                 }
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 /* ----------    Les macros suivantes ne doivent pas deja exister !              ---------- */
00110 
00111 # ifdef EXECUTION
00112 # error EXECUTION already defined
00113 # endif
00114 # ifdef INTERRUPTION
00115 # error INTERRUPTION already defined
00116 # endif
00117 # ifdef ISCRUTE
00118 # error ISCRUTE already defined
00119 # endif
00120 # ifdef RSCRUTE
00121 # error RSCRUTE already defined
00122 # endif
00123 # ifdef SSCRUTE
00124 # error SSCRUTE already defined
00125 # endif
00126 # ifdef CSCRUTE
00127 # error CSCRUTE already defined
00128 # endif
00129 # ifdef XSCRUTE
00130 # error XSCRUTE already defined
00131 # endif
00132 # ifdef MESSAGE
00133 # error MESSAGE already defined
00134 # endif
00135 
00136 
00137 
00138 /* Définition du format à utiliser pour afficher un med_int */
00139 # define IFORMAT_int "%d"
00140 # define IFORMAT_long "%ld"
00141 # define IFORMAT IFORMAT_long
00142 
00143 #if ! defined(MESGERR)
00144 #error "Explicit error messages must be either activated or deactivated, hence MESGERR macro must be defined."
00145 #error "Verify that you include med_utils.h after med_config.h, thanks."
00146 #endif
00147 
00148 # if MESGERR == 1
00149 
00150 
00151 /* --- Pour tracer sur la stderr l'execution d"une instruction.                         --- */
00152 
00153 # define EXECUTION(instruction) {\
00154                                         ICI ;\
00155                                         fprintf( stderr,"INSTRUCTION %s" , #instruction ) ;\
00156                                         fflush(stderr);\
00157                                         instruction ;\
00158                                         fflush(stdout);\
00159                                         fprintf( stderr," FRANCHIE\n" ) ;\
00160                                         fflush(stderr);\
00161                                 }
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 /* --- Pour afficher un message d'interruption volontaire et retourner le code retour   --- */
00170 /* --- "code"                                                                           --- */
00171 
00172 # define INTERRUPTION(code)     {\
00173                                         ICI ;\
00174                                         fprintf( stderr," INTERRUPTION code = %d",code) ;\
00175                                         fprintf(stderr,"\n") ;\
00176                                         exit(code) ;\
00177                                 }
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 /* --- Pour conditionner la poursuite du traitement par la validite de la condition     --- */
00186 /* --- "condition".                                                                     --- */
00187 
00188 # ifndef ASSERT
00189 # define ASSERT(condition)      if( !(condition) ){\
00190                                         ICI ;\
00191                                         fprintf(stderr,"condition %s VIOLEE\n",#condition);\
00192                                         INTERRUPTION(17);\
00193                                 }
00194 # endif         /* # ifndef ASSERT */
00195 
00196 
00197 /* --- Pour conditionner la poursuite du traitement au fait qu'une chaine ne finie pas par un blanc --- */
00198 /* --- "nofinalblank".                                                                              --- */
00199 # ifndef NOFINALBLANK
00200 # define NOFINALBLANK(chaine,label) if( ( chaine[strlen(chaine)-1] == ' ' ) ){ \
00201                                         ICI ;\
00202                                         fprintf(stderr,"La chaine |%s| ne doit pas finir par un caractère blanc.\n",chaine);\
00203                                         goto label;                     \
00204                                 }
00205 # endif         /* # ifndef NOFINALBLANK */
00206 
00207 
00208 
00209 
00210 
00211 
00212 /* --- Pour afficher sur la stderr la valeur d'une variable precedee de son nom.        --- */
00213 
00214 # define ISCRUTE(entier)        ISCRUTE_long(entier)
00215 
00216 # define ISCRUTE_int(entier)    {\
00217                                         ICI ;\
00218                                         fprintf(stderr,"%s = %d\n",#entier,entier) ;\
00219                                         fflush(stderr) ;\
00220                                 }
00221 # define ISCRUTE_long(entier)   {\
00222                                         ICI ;\
00223                                         fprintf(stderr,"%s = %ld\n",#entier,entier) ;\
00224                                         fflush(stderr) ;\
00225                                 }
00226 # define ISCRUTE_llong(entier)  {\
00227                                         ICI ;\
00228                                         fprintf(stderr,"%s = %lld\n",#entier,entier) ;\
00229                                         fflush(stderr) ;\
00230                                 }
00231 # define ISCRUTE_size(entier)   {\
00232                                         ICI ;\
00233                                         fprintf(stderr,"%s = %llu\n",#entier,entier) ;\
00234                                         fflush(stderr) ;\
00235                                 }
00236 # define ISCRUTE_id(entier) ISCRUTE_int(entier)
00237 # define RSCRUTE(reel)          {\
00238                                         ICI ;\
00239                                         fprintf(stderr,"%s = %f\n",#reel,reel) ;\
00240                                         fflush(stderr) ;\
00241                                 }
00242 # define XSCRUTE(pointeur)              {\
00243                                         ICI ;\
00244                                         fprintf(stderr,"%s = %x\n",#pointeur,pointeur) ;\
00245                                         fflush(stderr) ;\
00246                                 }
00247 # define CSCRUTE(car)           {\
00248                                         ICI ;\
00249                                         fprintf(stderr,"%s = %c\n",#car,car) ;\
00250                                         fflush(stderr) ;\
00251                                 }
00252 # define SSCRUTE(chaine)        {\
00253                                         ICI ;\
00254                                         fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
00255                                         fflush(stderr) ;\
00256                                 }
00257 # define MESSAGE(chaine)        {\
00258                                         ICI ;\
00259                                         fprintf(stderr,"%s\n",chaine) ;\
00260                                         fflush(stderr) ;\
00261                                 }
00262 # define FIN(nom)               {\
00263                                         ICI ;\
00264                                         fprintf( stderr , "} FIN %s\n\n\n" , nom ) ;\
00265                                         fflush(stderr) ;\
00266                                 }
00267 # define DEBUT(nom)             {\
00268                                         fprintf( stderr , "\n\n\n") ;\
00269                                         ICI ;\
00270                                         fprintf( stderr , "{ DEBUT %s\n" , nom ) ;\
00271                                         fflush(stderr) ;\
00272                                 }
00273 
00274 # ifdef WITH_EXCEPTIONS
00275 #   ifdef __cplusplus
00276 #    define EXIT_IF(expression,message,arg) {\
00277            if (expression != 0)                                         \
00278              throw MEDerreur(__FILE__,__LINE__,message,arg); }
00279 #   else
00280 #     error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
00281 #   endif
00282 # else
00283 # define EXIT_IF(expression,message,arg) { exit_if(__FILE__,__LINE__,expression,message,arg); }
00284 # endif
00285 
00286 
00287 
00288 # else          /* # if MESGERR */
00289 
00290 
00291 
00292 # define EXECUTION(instruction) instruction
00293 # define INTERRUPTION(code)
00294 
00295 # ifndef ASSERT
00296 # define ASSERT(condition)
00297 # endif
00298 
00299 # define NOFINALBLANK(chaine,label)
00300 
00301 # define ISCRUTE(entier)
00302 # define ISCRUTE_int(entier)
00303 # define ISCRUTE_long(entier)
00304 # define ISCRUTE_llong(entier)
00305 # define ISCRUTE_size(entier)
00306 # define ISCRUTE_id(entier)
00307 # define RSCRUTE(reel)
00308 # define CSCRUTE(car)
00309 # define SSCRUTE(chaine)
00310 # define MESSAGE(chaine)
00311 # define DEBUT(nom)
00312 # define FIN(nom)
00313 # define EXIT_IF(expression,message,arg)
00314 
00315 # endif         /* # if MESGERR */
00316 
00317 
00318 # endif         /* # ifndef __UTILITES_H__ */

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