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

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1