Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d910eb91c924b8338ac61a64fca08f085f90da33
[simgrid.git] / src / nws_portability / Include / diagnostic.h
1 /* $Id$ */
2
3
4 #ifndef DIAGNOSTIC_H
5 #define DIAGNOSTIC_H
6
7
8 /*
9  * This module manages the production of diagnostic messages.
10  */
11
12
13 #include <stdio.h> /* FILE */
14
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20
21 /*
22 ** Different types of diagnostics.
23 */
24 typedef enum {DIAGLOG, DIAGINFO, DIAGWARN, DIAGERROR, DIAGFATAL, DIAGDEBUG} DiagLevels;
25
26
27 #define DIAGSUPPRESS 0
28
29 /* 
30  * Maximum size for the message and for filenames
31  */
32 #define MAX_MESSAGE_LENGTH 512
33 #define MAX_FILENAME_LENGTH 512
34
35 /*
36 ** Directs #level#-level diagnostic messages to the file #whereTo#.  Messages
37 ** for any level may be supressed by passing DIAGSUPPRESS as the second
38 ** parameter to this routine.  By default, all messages are suppressed.
39 */
40 void
41 DirectDiagnostics(DiagLevels level,
42                   FILE *whereTo);
43
44
45 /*
46 ** Returns the file to which #level#-level diagnostics are being directed.  May
47 ** be used to save off the direction for a change/restore, or for writing out
48 ** non-message-based information.
49 */
50 FILE *
51 DiagnosticsDirection(DiagLevels level);
52
53
54 /*
55 ** Produces the #level#-level diagnostic message #message#, which is used as
56 ** the format string in a call to fprintf().  #sourcefilename# and
57 ** #sourcelinenumber# are appended to the message.  Additional fprintf()
58 ** arguments may be passed after #message#.
59 */
60 void
61 PositionedDiagnostic(DiagLevels level,
62                      const char *fileName, 
63                      int line,
64                      const char *message,
65                      ...);
66
67
68 /*
69 ** Produces the #level#-level diagnostic message #message#, which is used as
70 ** the format string in a call to fprintf().  Additional fprintf()
71 ** arguments may be passed after #message#.
72 */
73 void
74 Diagnostic(DiagLevels level,
75            const char *message,
76            ...);
77
78
79 /*
80 ** These macros are provided for the usual case where DIAGFATAL messages are
81 ** emitted just before aborting the program and DIAGERROR messages just before
82 ** returning a failure value from a function.  The ERROR, WARN, INFO, and LOG
83 ** macros are just a handy shorthand.  Unfortunately, the varargs concept
84 ** doesn't extend to macros, which means separate macros have to be defined for
85 ** various parameter counts.  The peculiar use of do ... while here prevents
86 ** compilation problems in cases such as:
87 ** if (foo < bar) FAIL("ick!"); else something();
88 ** The embedded if (1) satisfies the picky compilers that complain about
89 ** execution not reaching the loop test otherwise.
90 */
91 #define ABORT(message) \
92   do { \
93     PositionedDiagnostic(DIAGFATAL,__FILE__, __LINE__,message); \
94     if (1) exit(1); \
95   } while (0)
96 #define ABORT1(message,a) \
97   do { \
98     PositionedDiagnostic(DIAGFATAL,__FILE__,__LINE__,message,a); \
99     if (1) exit(1); \
100   } while (0)
101 #define ABORT2(message,a,b) \
102   do { \
103     PositionedDiagnostic(DIAGFATAL,__FILE__,__LINE__,message,a,b); \
104     if (1) exit(1); \
105   } while (0)
106 #define ABORT3(message,a,b,c) \
107   do { \
108     PositionedDiagnostic(DIAGFATAL,__FILE__,__LINE__,message,a,b,c); \
109     if (1) exit(1); \
110   } while (0)
111 #define ABORT4(message,a,b,c,d) \
112   do { \
113     PositionedDiagnostic(DIAGFATAL,__FILE__,__LINE__,message,a,b,c,d); \
114     if (1) exit(1); \
115   } while (0)
116 #define ABORT5(message,a,b,c,d,e) \
117   do { \
118     PositionedDiagnostic(DIAGFATAL,__FILE__,__LINE__,message,a,b,c,d,e); \
119     if (1) exit(1); \
120   } while (0)
121
122 #define FAIL(message) \
123   do { \
124     PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message); \
125     if (1) return(0); \
126   } while (0)
127 #define FAIL1(message,a) \
128   do { \
129     PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a); \
130     if (1) return(0); \
131   } while (0)
132 #define FAIL2(message,a,b) \
133   do { \
134     PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b); \
135     if (1) return(0); \
136   } while (0)
137 #define FAIL3(message,a,b,c) \
138   do { \
139     PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c); \
140     if (1) return(0); \
141   } while (0)
142 #define FAIL4(message,a,b,c,d) \
143   do { \
144     PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c,d); \
145     if (1) return(0); \
146   } while (0)
147 #define FAIL5(message,a,b,c,d,e) \
148   do {PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c,d,e); \
149     if (1) return(0); \
150   } while (0)
151
152 #define ERROR(message) \
153   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message)
154 #define ERROR1(message,a) \
155   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a)
156 #define ERROR2(message,a,b) \
157   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b)
158 #define ERROR3(message,a,b,c) \
159   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c)
160 #define ERROR4(message,a,b,c,d) \
161   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c,d)
162 #define ERROR5(message,a,b,c,d,e) \
163   PositionedDiagnostic(DIAGERROR,__FILE__,__LINE__,message,a,b,c,d,e)
164
165 #define WARN(message) \
166   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message)
167 #define WARN1(message,a) \
168   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message,a)
169 #define WARN2(message,a,b) \
170   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message,a,b)
171 #define WARN3(message,a,b,c) \
172   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message,a,b,c)
173 #define WARN4(message,a,b,c,d) \
174   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message,a,b,c,d)
175 #define WARN5(message,a,b,c,d,e) \
176   PositionedDiagnostic(DIAGWARN,__FILE__,__LINE__,message,a,b,c,d,e)
177
178 #define INFO(message) \
179   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message)
180 #define INFO1(message,a) \
181   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message,a)
182 #define INFO2(message,a,b) \
183   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message,a,b)
184 #define INFO3(message,a,b,c) \
185   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message,a,b,c)
186 #define INFO4(message,a,b,c,d) \
187   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message,a,b,c,d)
188 #define INFO5(message,a,b,c,d,e) \
189   PositionedDiagnostic(DIAGINFO,__FILE__,__LINE__,message,a,b,c,d,e)
190
191 #define LOG(message) \
192   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message)
193 #define LOG1(message,a) \
194   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message,a)
195 #define LOG2(message,a,b) \
196   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message,a,b)
197 #define LOG3(message,a,b,c) \
198   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message,a,b,c)
199 #define LOG4(message,a,b,c,d) \
200   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message,a,b,c,d)
201 #define LOG5(message,a,b,c,d,e) \
202   PositionedDiagnostic(DIAGLOG,__FILE__,__LINE__,message,a,b,c,d,e)
203
204 /* /usr/include/macros.h defines a DEBUG macro, so we use DDEBUG instead. */
205 #define DDEBUG(message) \
206   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message)
207 #define DDEBUG1(message,a) \
208   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message,a)
209 #define DDEBUG2(message,a,b) \
210   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message,a,b)
211 #define DDEBUG3(message,a,b,c) \
212   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message,a,b,c)
213 #define DDEBUG4(message,a,b,c,d) \
214   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message,a,b,c,d)
215 #define DDEBUG5(message,a,b,c,d,e) \
216   PositionedDiagnostic(DIAGDEBUG,__FILE__,__LINE__,message,a,b,c,d,e)
217
218 #ifdef __cplusplus
219 }
220 #endif
221
222
223 #endif