MED fichier
build.python2/include/med_utils.h
Aller à la documentation de ce fichier.
1 /* -*- mode:C; coding:utf-8 -*- */
2 /* This file is part of MED.
3  *
4  * COPYRIGHT (C) 1999 - 2019 EDF R&D, CEA/DEN
5  * MED is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * MED is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MED. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 # ifndef __UTILITES_H__
21 # define __UTILITES_H__
22 
23 #include <stdlib.h>
24 #include <med_exit_if.h>
25 #include <med_err.h>
26 
27 /* pour indiquer le statut des arguments des fonctions. */
28 
29 #ifdef _IN
30 #error _IN already defined
31 #endif
32 #define _IN
33 
34 #ifdef _OUT
35 #error _OUT already defined
36 #endif
37 #define _OUT
38 
39 #ifdef _INOUT
40 #error _INOUT already defined
41 #endif
42 #define _INOUT
43 
44 #ifdef _UNUSED
45 #error _UNUSED already defined
46 #endif
47 #define _UNUSED
48 
49 
50 
51 
52 
53 
54 
55 /* --- Pour afficher le nom du fichier source courant et le numero de la ligne courante --- */
56 /* --- sur la stderr. --- */
57 
58 # define ICI {\
59  fflush(stdout);\
60  fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
61  fflush(stderr) ;\
62  }
63 
64 
65 
66 
67 
68 
69 
70 /* --- Pour afficher la date et l'heure de la compilation du fichier source courant, --- */
71 /* --- sur la stdout. --- */
72 
73 # ifdef INFOS_COMPILATION
74 # error INFOS_COMPILATION already defined
75 # endif
76 # define INFOS_COMPILATION {\
77  fflush(stderr);\
78  fprintf(stdout, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
79  fprintf(stdout,"Compilation le %s" , __DATE__);\
80  fprintf(stdout," a %s" , __TIME__ );\
81  fprintf(stdout,"\n\n\n" );\
82  fflush(stdout) ;\
83  }
84 
85 
86 
87 
88 
89 
90 
91 /* --- Pour attendre "secondes" secondes et afficher un message sur la stderr indiquant --- */
92 /* --- cette attente volontaire. --- */
93 
94 # ifdef ATTENTE
95 # error ATTENTE already defined
96 # endif
97 # define ATTENTE(secondes) {\
98  ICI ;\
99  fprintf( stderr, "ATTENTE de %d secondes" , secondes);\
100  fflush(stderr) ;\
101  sleep(secondes) ;\
102  fprintf( stderr, "\n" );\
103  fflush(stderr) ;\
104  }
105 
106 
107 
108 
109 
110 
111 
112 /* ---------- Les macros suivantes ne doivent pas deja exister ! ---------- */
113 
114 # ifdef EXECUTION
115 # error EXECUTION already defined
116 # endif
117 # ifdef INTERRUPTION
118 # error INTERRUPTION already defined
119 # endif
120 # ifdef ISCRUTE
121 # error ISCRUTE already defined
122 # endif
123 # ifdef RSCRUTE
124 # error RSCRUTE already defined
125 # endif
126 # ifdef SSCRUTE
127 # error SSCRUTE already defined
128 # endif
129 # ifdef CSCRUTE
130 # error CSCRUTE already defined
131 # endif
132 # ifdef XSCRUTE
133 # error XSCRUTE already defined
134 # endif
135 # ifdef MESSAGE
136 # error MESSAGE already defined
137 # endif
138 
139 
140 
141 /* D馩nition du format ?tiliser pour afficher un med_int */
142 # define IFORMAT_int "%d"
143 # define IFORMAT_long "%ld"
144 # define IFORMAT IFORMAT_int
145 
149 # define MED_IFORMAT_int "d"
150 # define MED_IFORMAT_long "ld"
151 # define MED_IFORMAT MED_IFORMAT_int
152 
157 #define MED_EXP2_(msg1,msg2) msg1 msg2
158 #define MED_ERR_(rt,r1,r2,r3) { rt = r1 r2; MESSAGE(MED_EXP2_(r1 ## _MSG,r2 ## _MSG)); MESSAGE(r3); }
159 
160 
161 #if ! defined(MESGERR)
162 #error "Explicit error messages must be either activated or deactivated, hence MESGERR macro must be defined."
163 #error "Verify that you include med_utils.h after med_config.h, thanks."
164 #endif
165 
166 # if MESGERR == 1 || defined(MED_MESGERR_FOR_TOOLS)
167 
168 
169 /* --- Pour tracer sur la stderr l'execution d"une instruction. --- */
170 
171 # define EXECUTION(instruction) {\
172  ICI ;\
173  fprintf( stderr,"INSTRUCTION %s" , #instruction ) ;\
174  fflush(stderr);\
175  instruction ;\
176  fflush(stdout);\
177  fprintf( stderr," FRANCHIE\n" ) ;\
178  fflush(stderr);\
179  }
180 
181 
182 
183 
184 
185 
186 
187 /* --- Pour afficher un message d'interruption volontaire et retourner le code retour --- */
188 /* --- "code" --- */
189 
190 # define INTERRUPTION(code) {\
191  ICI ;\
192  fprintf( stderr," INTERRUPTION code = %d",code) ;\
193  fprintf(stderr,"\n") ;\
194  exit(code) ;\
195  }
196 
197 
198 
199 
200 
201 
202 
203 /* --- Pour conditionner la poursuite du traitement par la validite de la condition --- */
204 /* --- "condition". --- */
205 
206 # ifndef ASSERT
207 # define ASSERT(condition) if( !(condition) ){\
208  ICI ;\
209  fprintf(stderr,"condition %s VIOLEE\n",#condition);\
210  INTERRUPTION(17);\
211  }
212 # endif /* # ifndef ASSERT */
213 
214 
215 /* --- Pour conditionner la poursuite du traitement au fait qu'une chaine ne finie pas par un blanc --- */
216 /* --- "nofinalblank". --- */
217 # ifndef NOFINALBLANK
218 # define NOFINALBLANK(chaine,label) if (chaine) if (strlen(chaine)) if( ( chaine[strlen(chaine)-1] == ' ' ) ){ \
219  ICI ;\
220  fprintf(stderr,"La chaine |%s| ne doit pas finir par un caract貥 blanc.\n",chaine);\
221  goto label; \
222  }
223 # endif /* # ifndef NOFINALBLANK */
224 
225 
226 
227 
228 
229 
230 /* --- Pour afficher sur la stderr la valeur d'une variable precedee de son nom. --- */
231 
232 # define ISCRUTE(entier) ISCRUTE_int(entier)
233 
234 # define ISCRUTE_int(entier) {\
235  ICI ;\
236  fprintf(stderr,"%s = %d\n",#entier,entier) ;\
237  fflush(stderr) ;\
238  }
239 # define ISCRUTE_long(entier) {\
240  ICI ;\
241  fprintf(stderr,"%s = %ld\n",#entier,entier) ;\
242  fflush(stderr) ;\
243  }
244 # define ISCRUTE_llong(entier) {\
245  ICI ;\
246  fprintf(stderr,"%s = %lld\n",#entier,entier) ;\
247  fflush(stderr) ;\
248  }
249 # define ISCRUTE_size(entier) {\
250  ICI ;\
251  fprintf(stderr,"%s = %llu\n",#entier,entier) ;\
252  fflush(stderr) ;\
253  }
254 # define ISCRUTE_id(entier) ISCRUTE_int(entier)
255 # define RSCRUTE(reel) {\
256  ICI ;\
257  fprintf(stderr,"%s = %f\n",#reel,reel) ;\
258  fflush(stderr) ;\
259  }
260 # define XSCRUTE(pointeur) {\
261  ICI ;\
262  fprintf(stderr,"%s = %p\n",#pointeur,pointeur) ;\
263  fflush(stderr) ;\
264  }
265 # define CSCRUTE(car) {\
266  ICI ;\
267  fprintf(stderr,"%s = %c\n",#car,car) ;\
268  fflush(stderr) ;\
269  }
270 # define SSCRUTE(chaine) {\
271  ICI ;\
272  fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
273  fflush(stderr) ;\
274  }
275 # define MESSAGE(chaine) {\
276  ICI ;\
277  fprintf(stderr,"%s\n",chaine) ;\
278  fflush(stderr) ;\
279  }
280 # define FIN(nom) {\
281  ICI ;\
282  fprintf( stderr , "} FIN %s\n\n\n" , nom ) ;\
283  fflush(stderr) ;\
284  }
285 # define DEBUT(nom) {\
286  fprintf( stderr , "\n\n\n") ;\
287  ICI ;\
288  fprintf( stderr , "{ DEBUT %s\n" , nom ) ;\
289  fflush(stderr) ;\
290  }
291 
292 
293 # else /* # if MESGERR != 1*/
294 
295 
296 
297 # define EXECUTION(instruction) instruction
298 # define INTERRUPTION(code)
299 
300 # ifndef ASSERT
301 # define ASSERT(condition)
302 # endif
303 
304 # define NOFINALBLANK(chaine,label)
305 
306 # define ISCRUTE(entier)
307 # define ISCRUTE_int(entier)
308 # define ISCRUTE_long(entier)
309 # define ISCRUTE_llong(entier)
310 # define ISCRUTE_size(entier)
311 # define ISCRUTE_id(entier)
312 # define XSCRUTE(pointeur)
313 # define RSCRUTE(reel)
314 # define CSCRUTE(car)
315 # define SSCRUTE(chaine)
316 # define MESSAGE(chaine)
317 # define DEBUT(nom)
318 # define FIN(nom)
319 
320 # endif /* # if MESGERR */
321 
322 /* Ces macros ne doivent être utilisées que dans les outils ou les tests.
323  Elles ne doivent pas être utilsées dans la bibliothèque (pour respecter l'option --disable-mesgerr).
324 */
325 
326 # ifdef WITH_EXCEPTIONS
327 # ifdef __cplusplus
328 # define EXIT_IF(expression,message,arg) {\
329  if ( ( expression ) != 0) \
330  throw MEDerreur(__FILE__,__LINE__,message,arg); }
331 # else
332 # error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
333 # endif
334 # else
335 # define EXIT_IF(expression,message,arg) { exit_if(__FILE__,__LINE__,expression,message,arg); }
336 # endif
337 
338 
339 # ifdef WITH_EXCEPTIONS
340 # ifdef __cplusplus
341 # define MED_ERR_EXIT_IF(expression,r1,r2,arg) {\
342  if ( ( expression ) != 0) \
343  throw MEDerreur(__FILE__,__LINE__,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
344 # else
345 # error Impossible d'activer l'option WITH_EXCEPTIONS avec un compilateur C
346 # endif
347 # else
348 # define MED_ERR_EXIT_IF(expression,r1,r2,arg) { exit_if(__FILE__,__LINE__,expression,MED_EXP2_(r1 ## _MSG,r2 ## _MSG),arg); }
349 # endif
350 
351 
352 # endif /* # ifndef __UTILITES_H__ */