|
Revision 2135, 2.4 kB
(checked in by karpet, 7 months ago)
|
make warnings optional
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#include <stdio.h> |
|---|
| 23 |
#include <stdlib.h> |
|---|
| 24 |
#include <stdarg.h> |
|---|
| 25 |
#include <errno.h> |
|---|
| 26 |
#include <err.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <libxml/globals.h> |
|---|
| 29 |
|
|---|
| 30 |
#include "libswish3.h" |
|---|
| 31 |
|
|---|
| 32 |
extern int SWISH_DEBUG; |
|---|
| 33 |
extern int SWISH_WARNINGS; |
|---|
| 34 |
|
|---|
| 35 |
static FILE *error_handle = NULL; |
|---|
| 36 |
|
|---|
| 37 |
void |
|---|
| 38 |
swish_set_error_handle( |
|---|
| 39 |
FILE * where |
|---|
| 40 |
) |
|---|
| 41 |
{ |
|---|
| 42 |
error_handle = where; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
void |
|---|
| 46 |
swish_croak( |
|---|
| 47 |
const char *file, |
|---|
| 48 |
int line, |
|---|
| 49 |
const char *func, |
|---|
| 50 |
char *msgfmt, |
|---|
| 51 |
... |
|---|
| 52 |
) |
|---|
| 53 |
{ |
|---|
| 54 |
va_list args; |
|---|
| 55 |
|
|---|
| 56 |
if (!error_handle) |
|---|
| 57 |
error_handle = stderr; |
|---|
| 58 |
|
|---|
| 59 |
va_start(args, msgfmt); |
|---|
| 60 |
fprintf(error_handle, "Swish ERROR %s:%d %s: ", file, line, func); |
|---|
| 61 |
vfprintf(error_handle, msgfmt, args); |
|---|
| 62 |
fprintf(error_handle, "\n"); |
|---|
| 63 |
va_end(args); |
|---|
| 64 |
|
|---|
| 65 |
if (!errno) |
|---|
| 66 |
errno = 1; |
|---|
| 67 |
|
|---|
| 68 |
exit(errno); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
void |
|---|
| 72 |
swish_warn( |
|---|
| 73 |
const char *file, |
|---|
| 74 |
int line, |
|---|
| 75 |
const char *func, |
|---|
| 76 |
char *msgfmt, |
|---|
| 77 |
... |
|---|
| 78 |
) |
|---|
| 79 |
{ |
|---|
| 80 |
va_list args; |
|---|
| 81 |
|
|---|
| 82 |
if (!error_handle) |
|---|
| 83 |
error_handle = stderr; |
|---|
| 84 |
|
|---|
| 85 |
if (!SWISH_WARNINGS) |
|---|
| 86 |
return; |
|---|
| 87 |
|
|---|
| 88 |
va_start(args, msgfmt); |
|---|
| 89 |
fprintf(error_handle, "Swish WARNING %s:%d %s: ", file, line, func); |
|---|
| 90 |
vfprintf(error_handle, msgfmt, args); |
|---|
| 91 |
fprintf(error_handle, "\n"); |
|---|
| 92 |
va_end(args); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
void |
|---|
| 96 |
swish_debug( |
|---|
| 97 |
const char *file, |
|---|
| 98 |
int line, |
|---|
| 99 |
const char *func, |
|---|
| 100 |
char *msgfmt, |
|---|
| 101 |
... |
|---|
| 102 |
) |
|---|
| 103 |
{ |
|---|
| 104 |
va_list args; |
|---|
| 105 |
|
|---|
| 106 |
if (!error_handle) |
|---|
| 107 |
error_handle = stderr; |
|---|
| 108 |
|
|---|
| 109 |
va_start(args, msgfmt); |
|---|
| 110 |
fprintf(error_handle, "Swish DEBUG %s:%d %s: ", file, line, func); |
|---|
| 111 |
vfprintf(error_handle, msgfmt, args); |
|---|
| 112 |
fprintf(error_handle, "\n"); |
|---|
| 113 |
va_end(args); |
|---|
| 114 |
} |
|---|