Lely core libraries  2.3.4
diag.h
Go to the documentation of this file.
1 
22 #ifndef LELY_UTIL_DIAG_H_
23 #define LELY_UTIL_DIAG_H_
24 
25 #include <lely/util/errnum.h>
26 
27 #include <stdarg.h>
28 #include <stddef.h>
29 
30 #ifndef LELY_UTIL_DIAG_INLINE
31 #if LELY_NO_DIAG
32 #define LELY_UTIL_DIAG_INLINE static inline
33 #else
34 #define LELY_UTIL_DIAG_INLINE
35 #endif
36 #endif
37 
39 struct floc {
41  const char *filename;
43  int line;
45  int column;
46 };
47 
60 };
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
76 typedef void diag_handler_t(void *handle, enum diag_severity severity, int errc,
77  const char *format, va_list ap) format_printf__(4, 0);
78 
90 typedef void diag_at_handler_t(void *handle, enum diag_severity severity,
91  int errc, const struct floc *at, const char *format, va_list ap)
92  format_printf__(5, 0);
93 
94 #if !LELY_NO_STDIO
95 
106 size_t floc_lex(struct floc *at, const char *begin, const char *end);
107 #endif
108 
126 int snprintf_floc(char *s, size_t n, const struct floc *at);
127 
128 #if !LELY_NO_DIAG
129 
139 void diag_get_handler(diag_handler_t **phandler, void **phandle);
140 
150 void diag_set_handler(diag_handler_t *handler, void *handle);
151 
162 void diag_at_get_handler(diag_at_handler_t **phandler, void **phandle);
163 
173 void diag_at_set_handler(diag_at_handler_t *handler, void *handle);
174 #endif // !LELY_NO_DIAG
175 
196 LELY_UTIL_DIAG_INLINE void diag(enum diag_severity severity, int errc,
197  const char *format, ...) format_printf__(3, 4);
198 
199 #if !LELY_NO_DIAG
200 
204 void vdiag(enum diag_severity severity, int errc, const char *format,
205  va_list ap) format_printf__(3, 0);
206 #endif
207 
233 LELY_UTIL_DIAG_INLINE void diag_at(enum diag_severity severity, int errc,
234  const struct floc *at, const char *format, ...)
235  format_printf__(4, 5);
236 
237 #if !LELY_NO_DIAG
238 
243 void vdiag_at(enum diag_severity severity, int errc, const struct floc *at,
244  const char *format, va_list ap) format_printf__(4, 0);
245 #endif
246 
253 LELY_UTIL_DIAG_INLINE void diag_if(enum diag_severity severity, int errc,
254  const struct floc *at, const char *format, ...)
255  format_printf__(4, 5);
256 
257 #if !LELY_NO_DIAG
258 
264 void vdiag_if(enum diag_severity severity, int errc, const struct floc *at,
265  const char *format, va_list ap) format_printf__(4, 0);
266 #endif
267 
268 #if !LELY_NO_DIAG
269 
274 void default_diag_handler(void *handle, enum diag_severity severity, int errc,
275  const char *format, va_list ap) format_printf__(4, 0);
276 
282 void default_diag_at_handler(void *handle, enum diag_severity severity,
283  int errc, const struct floc *at, const char *format, va_list ap)
284  format_printf__(5, 0);
285 
290 void daemon_diag_handler(void *handle, enum diag_severity severity, int errc,
291  const char *format, va_list ap);
292 
298 void daemon_diag_at_handler(void *handle, enum diag_severity severity, int errc,
299  const struct floc *at, const char *format, va_list ap);
300 
306 void cmd_diag_handler(void *handle, enum diag_severity severity, int errc,
307  const char *format, va_list ap) format_printf__(4, 0);
308 
314 void dialog_diag_handler(void *handle, enum diag_severity severity, int errc,
315  const char *format, va_list ap) format_printf__(4, 0);
316 
322 void dialog_diag_at_handler(void *handle, enum diag_severity severity, int errc,
323  const struct floc *at, const char *format, va_list ap)
324  format_printf__(5, 0);
325 
331 void log_diag_handler(void *handle, enum diag_severity severity, int errc,
332  const char *format, va_list ap) format_printf__(4, 0);
333 
339 void log_diag_at_handler(void *handle, enum diag_severity severity, int errc,
340  const struct floc *at, const char *format, va_list ap)
341  format_printf__(5, 0);
342 
348 void syslog_diag_handler(void *handle, enum diag_severity severity, int errc,
349  const char *format, va_list ap) format_printf__(4, 0);
350 
356 void syslog_diag_at_handler(void *handle, enum diag_severity severity, int errc,
357  const struct floc *at, const char *format, va_list ap)
358  format_printf__(5, 0);
359 
387 int vsnprintf_diag(char *s, size_t n, enum diag_severity severity, int errc,
388  const char *format, va_list ap) format_printf__(5, 0);
389 
412 int vasprintf_diag(char **ps, enum diag_severity severity, int errc,
413  const char *format, va_list ap) format_printf__(4, 0);
414 
447 int vsnprintf_diag_at(char *s, size_t n, enum diag_severity severity, int errc,
448  const struct floc *at, const char *format, va_list ap)
449  format_printf__(6, 0);
450 
476 int vasprintf_diag_at(char **ps, enum diag_severity severity, int errc,
477  const struct floc *at, const char *format, va_list ap)
478  format_printf__(5, 0);
479 
480 #endif // !LELY_NO_DIAG
481 
482 #if !LELY_NO_STDIO
483 
487 const char *cmdname(const char *path);
488 #endif
489 
490 #if LELY_NO_DIAG
491 
492 LELY_UTIL_DIAG_INLINE void
493 diag(enum diag_severity severity, int errc, const char *format, ...)
494 {
495  (void)severity;
496  (void)errc;
497  (void)format;
498 }
499 
500 LELY_UTIL_DIAG_INLINE void
501 diag_at(enum diag_severity severity, int errc, const struct floc *at,
502  const char *format, ...)
503 {
504  (void)severity;
505  (void)errc;
506  (void)at;
507  (void)format;
508 }
509 
510 LELY_UTIL_DIAG_INLINE void
511 diag_if(enum diag_severity severity, int errc, const struct floc *at,
512  const char *format, ...)
513 {
514  (void)severity;
515  (void)errc;
516  (void)at;
517  (void)format;
518 }
519 
520 #endif // LELY_NO_DIAG
521 
522 #ifdef __cplusplus
523 }
524 #endif
525 
526 #endif // !LELY_UTIL_DIAG_H_
diag_severity
diag_severity
The severity of a diagnostic message.
Definition: diag.h:49
diag_at
void diag_at(enum diag_severity severity, int errc, const struct floc *at, const char *format,...)
Emits a diagnostic message occurring at a location in a text file.
Definition: diag.c:187
default_diag_handler
void default_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The default diag() handler.
Definition: diag.c:223
daemon_diag_handler
void daemon_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The diag() handler for daemons.
Definition: diag.c:273
DIAG_INFO
@ DIAG_INFO
An informational message.
Definition: diag.h:53
diag_at_get_handler
void diag_at_get_handler(diag_at_handler_t **phandler, void **phandle)
Retrieves the handler function for diag_at().
Definition: diag.c:155
log_diag_at_handler
void log_diag_at_handler(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The diag_at() handler used for log-files.
Definition: diag.c:342
diag_at_set_handler
void diag_at_set_handler(diag_at_handler_t *handler, void *handle)
Sets the handler function for diag_at().
Definition: diag.c:164
log_diag_handler
void log_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The diag() handler for log files.
Definition: diag.c:335
syslog_diag_handler
void syslog_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The diag() handler used for the system logging facilities.
Definition: diag.c:377
DIAG_FATAL
@ DIAG_FATAL
A fatal error, which SHOULD result in program termination.
Definition: diag.h:59
floc
A location in a text file.
Definition: diag.h:39
diag_get_handler
void diag_get_handler(diag_handler_t **phandler, void **phandle)
Retrieves the handler function for diag().
Definition: diag.c:139
diag_set_handler
void diag_set_handler(diag_handler_t *handler, void *handle)
Sets the handler function for diag().
Definition: diag.c:148
floc_lex
size_t floc_lex(struct floc *at, const char *begin, const char *end)
Increments a file location by reading characters from a memory buffer.
Definition: diag.c:65
vasprintf_diag_at
int vasprintf_diag_at(char **ps, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
Equivalent to vsnprintf_diag_at(), except that it allocates a string large enough to hold the output,...
Definition: diag.c:502
syslog_diag_at_handler
void syslog_diag_at_handler(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The diag_at() handler used for the system logging facilities.
Definition: diag.c:384
DIAG_ERROR
@ DIAG_ERROR
An error.
Definition: diag.h:57
floc::line
int line
The line number (starting from 1).
Definition: diag.h:43
default_diag_at_handler
void default_diag_at_handler(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The default diag_at() handler.
Definition: diag.c:230
floc::column
int column
The column number (starting from 1).
Definition: diag.h:45
dialog_diag_at_handler
void dialog_diag_at_handler(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The diag_at() handler for dialog boxes.
DIAG_WARNING
@ DIAG_WARNING
A warning.
Definition: diag.h:55
errnum.h
vdiag
void vdiag(enum diag_severity severity, int errc, const char *format, va_list ap)
Emits a diagnostic message.
Definition: diag.c:180
vasprintf_diag
int vasprintf_diag(char **ps, enum diag_severity severity, int errc, const char *format, va_list ap)
Equivalent to vsnprintf_diag(), except that it allocates a string large enough to hold the output,...
Definition: diag.c:421
vsnprintf_diag_at
int vsnprintf_diag_at(char *s, size_t n, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
Prints a diagnostic message occurring at a location in a text file to a string buffer.
Definition: diag.c:428
diag_handler_t
void diag_handler_t(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The function type of a handler for diag().
Definition: diag.h:76
daemon_diag_at_handler
void daemon_diag_at_handler(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The diag_at() handler for daemons.
Definition: diag.c:280
DIAG_DEBUG
@ DIAG_DEBUG
A debug message.
Definition: diag.h:51
diag
void diag(enum diag_severity severity, int errc, const char *format,...)
Emits a diagnostic message.
Definition: diag.c:171
vdiag_at
void vdiag_at(enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
Emits a diagnostic message occurring at a location in a text file.
Definition: diag.c:197
cmdname
const char * cmdname(const char *path)
Extracts the command name from a path.
Definition: diag.c:537
vsnprintf_diag
int vsnprintf_diag(char *s, size_t n, enum diag_severity severity, int errc, const char *format, va_list ap)
Prints a diagnostic message to a string buffer.
Definition: diag.c:414
cmd_diag_handler
void cmd_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The diag() handler used for command-line programs.
Definition: diag.c:258
dialog_diag_handler
void dialog_diag_handler(void *handle, enum diag_severity severity, int errc, const char *format, va_list ap)
The diag() handler for dialog boxes.
snprintf_floc
int snprintf_floc(char *s, size_t n, const struct floc *at)
Prints a file location to a string buffer.
Definition: diag.c:97
diag_at_handler_t
void diag_at_handler_t(void *handle, enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
The function type of a handler for diag_at().
Definition: diag.h:90
diag_if
void diag_if(enum diag_severity severity, int errc, const struct floc *at, const char *format,...)
Emits a diagnostic message occurring at a location in a text file.
Definition: diag.c:205
floc::filename
const char * filename
The name of the file.
Definition: diag.h:41
vdiag_if
void vdiag_if(enum diag_severity severity, int errc, const struct floc *at, const char *format, va_list ap)
Emits a diagnostic message occurring at a location in a text file.
Definition: diag.c:215
stddef.h