1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#include "fitz.h"
enum { LINELEN = 160, LINECOUNT = 25 };
static char warnmessage[LINELEN] = "";
static int warncount = 0;
void fz_flushwarnings(void)
{
if (warncount > 1)
fprintf(stderr, "warning: ... repeated %d times ...\n", warncount);
warnmessage[0] = 0;
warncount = 0;
}
void fz_warn(char *fmt, ...)
{
va_list ap;
char buf[LINELEN];
va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
if (!strcmp(buf, warnmessage))
{
warncount++;
}
else
{
fz_flushwarnings();
fprintf(stderr, "warning: %s\n", buf);
fz_strlcpy(warnmessage, buf, sizeof warnmessage);
warncount = 1;
}
}
fz_error
fz_throwimp(const char *file, int line, const char *func, char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "+ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
return -1;
}
fz_error
fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "| %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
return cause;
}
void
fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "\\ %s:%d: %s(): ", file, line, func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
}
fz_error
fz_throwimpx(char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "+ ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
return -1;
}
fz_error
fz_rethrowimpx(fz_error cause, char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "| ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
return cause;
}
void
fz_catchimpx(fz_error cause, char *fmt, ...)
{
va_list ap;
fz_flushwarnings();
fprintf(stderr, "\\ ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
}
|