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