00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00056
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
00071
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
00092
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
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
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
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
00177
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
00193
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
00202
00203
00204
00205
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
00213
00214
00215
00216
00217
00218
00219
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
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
00337
00338
00339 # endif