output.c

Mon, 17 Jan 2005 22:02:09 +0100

author
tuomov
date
Mon, 17 Jan 2005 22:02:09 +0100
changeset 85
9f94b2e96e3b
parent 84
77a9dc0a2140
child 109
96a557abc364
permissions
-rw-r--r--

trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.

0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
1 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
2 * libtu/output.c
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
3 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 35
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
53
f8f9366b359c trunk: changeset 57
tuomov
parents: 52
diff changeset
5 *
f8f9366b359c trunk: changeset 57
tuomov
parents: 52
diff changeset
6 * You may distribute and modify this library under the terms of either
f8f9366b359c trunk: changeset 57
tuomov
parents: 52
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
8 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
9
55
d32ef6ce17a4 trunk: changeset 59
tuomov
parents: 53
diff changeset
10 #if defined(HAS_SYSTEM_ASPRINTF)
d32ef6ce17a4 trunk: changeset 59
tuomov
parents: 53
diff changeset
11 #define _GNU_SOURCE
d32ef6ce17a4 trunk: changeset 59
tuomov
parents: 53
diff changeset
12 #endif
d32ef6ce17a4 trunk: changeset 59
tuomov
parents: 53
diff changeset
13
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
14 #include <stdio.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
15 #include <stdlib.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
16 #include <errno.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
17 #include <strings.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
18 #include <string.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
19
70
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
20 #include "misc.h"
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
21 #include "output.h"
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
22 #include "util.h"
79
81e9a32b1c0c trunk: changeset 1689
tuomov
parents: 70
diff changeset
23 #include "private.h"
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
24
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
25 #if !defined(HAS_SYSTEM_ASPRINTF)
59
d8ecbeda7683 trunk: changeset 1306
tuomov
parents: 55
diff changeset
26 #include "snprintf_2.2/snprintf.h"
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
27 #endif
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
28
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
29
52
0228b3741a42 trunk: changeset 56
tuomov
parents: 36
diff changeset
30 static void default_warn_handler(const char *message);
0228b3741a42 trunk: changeset 56
tuomov
parents: 36
diff changeset
31
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
32
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
33 static bool verbose_mode=FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
34 static int verbose_indent_lvl=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
35 static bool progname_enable=TRUE;
52
0228b3741a42 trunk: changeset 56
tuomov
parents: 36
diff changeset
36 static WarnHandler *current_warn_handler=default_warn_handler;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
37
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
38 #define INDENTATOR_LENGTH 4
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
39
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
40 static char indentator[]={' ', ' ', ' ', ' '};
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
41
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
42 static void do_dispatch_message(const char *message);
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
43
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
44
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
45 void verbose(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
46 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
47 va_list args;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
48
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
49 va_start(args, p);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
50
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
51 verbose_v(p, args);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
52
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
53 va_end(args);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
54 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
55
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
56
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
57 void verbose_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
58 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
59 int i;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
60
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
61 if(verbose_mode){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
62 for(i=0; i<verbose_indent_lvl; i++)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
63 writef(stdout, indentator, INDENTATOR_LENGTH);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
64
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
65 vprintf(p, args);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
66 fflush(stdout);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
67 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
68 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
69
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
70
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
71 void verbose_enable(bool enable)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
72 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
73 verbose_mode=enable;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
74 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
75
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
76
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
77 int verbose_indent(int depth)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
78 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
79 int old=verbose_indent_lvl;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
80
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
81 if(depth>=0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
82 verbose_indent_lvl=depth;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
83
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
84 return old;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
85 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
86
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
87
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
88 void warn_progname_enable(bool enable)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
89 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
90 progname_enable=enable;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
91 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
92
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
93
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
94 static void put_prog_name()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
95 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
96 const char*progname;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
97
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
98 if(!progname_enable)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
99 return;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
100
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
101 progname=prog_execname();
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
102
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
103 if(progname==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
104 return;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
105
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
106 fprintf(stderr, "%s: ", (char*)progname);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
107 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
108
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
109 /* warn
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
110 */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
111
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
112
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
113 static void fallback_warn()
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
114 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
115 put_prog_name();
84
77a9dc0a2140 trunk: changeset 1814
tuomov
parents: 83
diff changeset
116 fprintf(stderr, TR("Oops. Error string compilation failed: %s"),
77a9dc0a2140 trunk: changeset 1814
tuomov
parents: 83
diff changeset
117 strerror(errno));
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
118 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
119
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
120
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
121 #define CALL_V(NAME, ARGS) \
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
122 do { va_list args; va_start(args, p); NAME ARGS; va_end(args); } while(0)
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
123
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
124 #define DO_DISPATCH(NAME, ARGS) \
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
125 do{ \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
126 char *msg; \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
127 if((msg=NAME ARGS)!=NULL){ \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
128 do_dispatch_message(msg); \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
129 free(msg);\
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
130 }else{ \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
131 fallback_warn(); \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
132 } \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
133 }while(0)
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
134
33
3a0064eb9421 trunk: changeset 36
tuomov
parents: 31
diff changeset
135
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
136 void libtu_asprintf(char **ret, const char *p, ...)
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
137 {
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
138 *ret=NULL;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
139 CALL_V(vasprintf, (ret, p, args));
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
140 if(*ret==NULL)
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
141 warn_err();
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
142 }
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
143
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
144
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
145 void libtu_vasprintf(char **ret, const char *p, va_list args)
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
146 {
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
147 *ret=NULL;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
148 vasprintf(ret, p, args);
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
149 if(*ret==NULL)
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
150 warn_err();
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
151 }
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
152
33
3a0064eb9421 trunk: changeset 36
tuomov
parents: 31
diff changeset
153
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154 void warn(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
155 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
156 CALL_V(warn_v, (p, args));
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
157 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
158
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
159
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
160 void warn_obj(const char *obj, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
161 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
162 CALL_V(warn_obj_v, (obj, p, args));
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
163 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
164
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
165
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
166 void warn_obj_line(const char *obj, int line, const char *p, ...)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
167 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
168 CALL_V(warn_obj_line_v, (obj, line, p, args));
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
169 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
170
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
171
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
172 void warn_obj_v(const char *obj, const char *p, va_list args)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
173 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
174 warn_obj_line_v(obj, -1, p, args);
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
175 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
176
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
177
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
178 void warn_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
179 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
180 DO_DISPATCH(errmsg_v, (p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
181 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
182
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
183
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
184 void warn_obj_line_v(const char *obj, int line, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
185 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
186 DO_DISPATCH(errmsg_obj_line_v, (obj, line, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
187 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
188
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
189
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
190 void warn_err()
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
191 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
192 DO_DISPATCH(errmsg_err, ());
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
193 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
194
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
195
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
196 void warn_err_obj(const char *obj)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
197 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
198 DO_DISPATCH(errmsg_err_obj, (obj));
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
199 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
200
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
201 void warn_err_obj_line(const char *obj, int line)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
202 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
203 DO_DISPATCH(errmsg_err_obj_line, (obj, line));
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
204 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
205
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
206
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
207 /* errmsg
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
208 */
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
209
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
210 #define CALL_V_RET(NAME, ARGS) \
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
211 char *ret; va_list args; va_start(args, p); ret=NAME ARGS; \
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
212 va_end(args); return ret;
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
213
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
214
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
215 char* errmsg(const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
216 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
217 CALL_V_RET(errmsg_v, (p, args));
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
218 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
219
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
220
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
221 char *errmsg_obj(const char *obj, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
222 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
223 CALL_V_RET(errmsg_obj_v, (obj, p, args));
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
224 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
225
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
226
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
227 char *errmsg_obj_line(const char *obj, int line, const char *p, ...)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
228 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
229 CALL_V_RET(errmsg_obj_line_v, (obj, line, p, args));
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
230 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
231
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
232
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
233 char* errmsg_obj_v(const char *obj, const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
234 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
235 return errmsg_obj_line_v(obj, -1, p, args);
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
236 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
237
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
238
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
239 char *errmsg_v(const char *p, va_list args)
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
240 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
241 char *res;
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
242 libtu_vasprintf(&res, p, args);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
243 return res;
27
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
244 }
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
245
228f64ffb422 trunk: changeset 30
tuomov
parents: 26
diff changeset
246
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
247 char *errmsg_obj_line_v(const char *obj, int line, const char *p, va_list args)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
248 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
249 char *res1=NULL, *res2, *res3;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
250
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
251 if(obj!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
252 if(line>0)
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
253 libtu_asprintf(&res1, "%s:%d: ", obj, line);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
254 else
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
255 libtu_asprintf(&res1, "%s: ", obj);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
256 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
257 if(line>0)
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
258 libtu_asprintf(&res1, "%d: ", line);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
259 }
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
260 libtu_vasprintf(&res2, p, args);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
261 if(res1!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
262 if(res2==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
263 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
264 res3=scat(res1, res2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
265 free(res1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
266 free(res2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
267 return res3;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
268 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
269 return res2;
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
270 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
271
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
272
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
273 char *errmsg_err()
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
274 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
275 char *res;
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
276 libtu_asprintf(&res, "%s\n", strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
277 return res;
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
278 }
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
279
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
280
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
281 char *errmsg_err_obj(const char *obj)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
282 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
283 char *res;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
284 if(obj!=NULL)
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
285 libtu_asprintf(&res, "%s: %s\n", obj, strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
286 else
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
287 libtu_asprintf(&res, "%s\n", strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
288 return res;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
289 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
290
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
291
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
292 char *errmsg_err_obj_line(const char *obj, int line)
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
293 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
294 char *res;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
295 if(obj!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
296 if(line>0)
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
297 libtu_asprintf(&res, "%s:%d: %s\n", obj, line, strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
298 else
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
299 libtu_asprintf(&res, "%s: %s\n", obj, strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
300 }else{
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
301 if(line>0)
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
302 libtu_asprintf(&res, "%d: %s\n", line, strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
303 else
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 79
diff changeset
304 libtu_asprintf(&res, "%s\n", strerror(errno));
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
305 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
306 return res;
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
307 }
31
e9cad8bd8ec8 trunk: changeset 34
tuomov
parents: 27
diff changeset
308
25
9d41e3611050 trunk: changeset 28
tuomov
parents: 9
diff changeset
309
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
310 /* die
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
311 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
312
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
313
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
314 void die(const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
315 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
316 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
317 CALL_V(die_v, (p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
318 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
319
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
320
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
321 void die_v(const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
322 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
323 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
324 warn_v(p, args);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
325 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
326 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
327
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
328
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
329 void die_obj(const char *obj, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
330 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
331 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
332 CALL_V(die_obj_v, (obj, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
333 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
334
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
335
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
336 void die_obj_line(const char *obj, int line, const char *p, ...)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
337 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
338 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
339 CALL_V(die_obj_line_v, (obj, line, p, args));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
340 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
341
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
343 void die_obj_v(const char *obj, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
344 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
345 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
346 warn_obj_v(obj, p, args);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
347 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
351 void die_obj_line_v(const char *obj, int line, const char *p, va_list args)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
353 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
354 warn_obj_line_v(obj, line, p, args);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
355 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
356 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
357
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
358
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
359 void die_err()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
360 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
361 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
362 warn_err();
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
363 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
364 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
365
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
366
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
367 void die_err_obj(const char *obj)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
368 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
369 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
370 warn_err_obj(obj);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
371 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
372 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
373
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
374
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
375 void die_err_obj_line(const char *obj, int line)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
376 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
377 set_warn_handler(NULL);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
378 warn_err_obj_line(obj, line);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
379 exit(EXIT_FAILURE);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
380 }
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
381
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
382
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
383 static void default_warn_handler(const char *message)
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
384 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
385 put_prog_name();
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
386 fprintf(stderr, "%s", message);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
387 putc('\n', stderr);
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
388 }
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
389
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
390
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
391 static void do_dispatch_message(const char *message)
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
392 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
393 if(current_warn_handler!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
394 current_warn_handler(message);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
395 else
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
396 default_warn_handler(message);
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
397 }
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
398
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
399
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
400 WarnHandler *set_warn_handler(WarnHandler *handler)
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
401 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
402 WarnHandler *old=current_warn_handler;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
403 current_warn_handler=(handler!=NULL ? handler : default_warn_handler);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 59
diff changeset
404 return old;
35
5a71d53d0228 trunk: changeset 38
tuomov
parents: 33
diff changeset
405 }

mercurial