blob: dbe18c219c857f845f83b794dd7525e0778160fa [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#include "asn1fix_internal.h"
Lev Walkin4efbfb72005-02-25 14:20:30 +00002#include "asn1fix.h"
Lev Walkinf15320b2004-06-03 03:38:44 +00003
4/* Print everything to stderr */
5static void _default_error_logger(int _severity, const char *fmt, ...);
6
7/*
8 * Internal check functions.
9 */
Lev Walkind24c62d2004-09-15 11:47:23 +000010static int asn1f_fix_module__phase_1(arg_t *arg);
11static int asn1f_fix_module__phase_2(arg_t *arg);
Lev Walkinf15320b2004-06-03 03:38:44 +000012static int asn1f_fix_simple(arg_t *arg); /* For INTEGER/ENUMERATED */
13static int asn1f_fix_constructed(arg_t *arg); /* For SEQUENCE/SET/CHOICE */
Lev Walkin1ef05162004-08-25 00:42:25 +000014static int asn1f_resolve_constraints(arg_t *arg); /* For subtype constraints */
15static int asn1f_check_constraints(arg_t *arg); /* For subtype constraints */
Lev Walkinf593f102005-02-22 07:59:59 +000016static int asn1f_check_duplicate(arg_t *arg);
Lev Walkin1dec5802005-03-04 09:02:27 +000017static int asn1f_apply_unique_index(arg_t *arg);
Lev Walkinf15320b2004-06-03 03:38:44 +000018
Lev Walkinb45e0672004-08-18 05:42:05 +000019arg_t a1f_replace_me_with_proper_interface_arg;
Lev Walkinf15320b2004-06-03 03:38:44 +000020
21/*
22 * Scan every module defined here in search for inconsistences.
23 */
24int
25asn1f_process(asn1p_t *asn, enum asn1f_flags flags,
26 error_logger_f error_logger) {
27 arg_t arg;
28 int fatals = 0;
29 int warnings = 0;
Lev Walkin4533a5f2005-03-18 04:22:41 +000030 int ret;
Lev Walkinf15320b2004-06-03 03:38:44 +000031
32 /*
33 * Check validity of arguments.
34 */
35 if(asn == NULL) {
36 errno = EINVAL;
37 return -1;
38 }
39
40 /*
41 * If errors handler is not specified, default to internal one.
42 */
43 if(error_logger == 0) {
44 error_logger = _default_error_logger;
45 }
46
47 memset(&arg, 0, sizeof(arg));
48 arg.asn = asn;
49 arg.eh = error_logger;
50
51 if(flags & A1F_DEBUG) {
52 arg.debug = arg.eh;
53 arg.debug(-1, "Called %s() with flags %d", __func__, flags);
54 flags &= ~A1F_DEBUG;
55 }
56
Lev Walkin5253da42004-08-20 13:25:56 +000057 /* Allow SIZE() constraint for INTEGER and other types */
58 if(flags & A1F_EXTENDED_SizeConstraint) {
59 arg.flags |= A1F_EXTENDED_SizeConstraint;
60 flags &= ~A1F_EXTENDED_SizeConstraint;
61 if(arg.debug) {
62 arg.debug(-1,
63 "Extended SizeConstraint support enabled");
64 }
65 }
66
Lev Walkinb45e0672004-08-18 05:42:05 +000067 a1f_replace_me_with_proper_interface_arg = arg;
68
Lev Walkinf15320b2004-06-03 03:38:44 +000069 /*
70 * Check that we haven't missed an unknown flag.
71 */
72 if(flags) {
73 errno = EINVAL;
74 return -1;
75 }
76
77 /*
78 * Process each module in the list.
Lev Walkinf593f102005-02-22 07:59:59 +000079 * PHASE I.
Lev Walkinf15320b2004-06-03 03:38:44 +000080 */
81 TQ_FOR(arg.mod, &(asn->modules), mod_next) {
Lev Walkin4533a5f2005-03-18 04:22:41 +000082 ret = asn1f_fix_module__phase_1(&arg);
Lev Walkinf15320b2004-06-03 03:38:44 +000083 /*
84 * These lines are used for illustration purposes.
85 * RET2RVAL() is used everywhere else.
86 */
87 if(ret == -1) fatals++;
88 if(ret == 1) warnings++;
89 }
Lev Walkinf593f102005-02-22 07:59:59 +000090 /* PHASE II. */
Lev Walkind24c62d2004-09-15 11:47:23 +000091 TQ_FOR(arg.mod, &(asn->modules), mod_next) {
Lev Walkin4533a5f2005-03-18 04:22:41 +000092 ret = asn1f_fix_module__phase_2(&arg);
Lev Walkind24c62d2004-09-15 11:47:23 +000093 if(ret == -1) fatals++;
94 if(ret == 1) warnings++;
95 }
96
97 memset(&a1f_replace_me_with_proper_interface_arg, 0, sizeof(arg_t));
Lev Walkinf15320b2004-06-03 03:38:44 +000098
99 /*
100 * Compute a return value.
101 */
102 return fatals?-1:warnings?1:0;
103}
104
105/*
106 * Check the internals of a single module.
107 */
108static int
Lev Walkind24c62d2004-09-15 11:47:23 +0000109asn1f_fix_module__phase_1(arg_t *arg) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000110 asn1p_expr_t *expr;
111 int rvalue = 0;
Lev Walkin1ef05162004-08-25 00:42:25 +0000112 int ret;
Lev Walkin4533a5f2005-03-18 04:22:41 +0000113 asn1p_module_t *omod;
114
115 /*
116 * Check that we don't have a similarly named module.
117 */
118 TQ_FOR(omod, &arg->asn->modules, mod_next) {
119 int sameNames;
120 if(omod == arg->mod) break;
Lev Walkinb36317c2005-08-12 10:09:10 +0000121 sameNames = strcmp(omod->ModuleName, arg->mod->ModuleName)?0:1;
Lev Walkin4533a5f2005-03-18 04:22:41 +0000122 if(omod->module_oid && arg->mod->module_oid) {
123 /* Compare only the OID. */
124 if(asn1p_oid_compare(omod->module_oid,
125 arg->mod->module_oid) == 0) {
Lev Walkin1a447952005-03-18 04:26:12 +0000126 FATAL("ASN.1 module %s in %s "
Lev Walkin4533a5f2005-03-18 04:22:41 +0000127 "has the same OBJECT IDENTIFIER"
Lev Walkin1a447952005-03-18 04:26:12 +0000128 " as module %s",
Lev Walkinb36317c2005-08-12 10:09:10 +0000129 omod->ModuleName,
Lev Walkin1a447952005-03-18 04:26:12 +0000130 omod->source_file_name,
Lev Walkinb36317c2005-08-12 10:09:10 +0000131 arg->mod->ModuleName
Lev Walkin4533a5f2005-03-18 04:22:41 +0000132 );
133 RET2RVAL(-1, rvalue);
134 } else if(sameNames) {
Lev Walkinb36317c2005-08-12 10:09:10 +0000135 WARNING("ASN.1 module %s is defined more than once, with different OIDs", omod->ModuleName);
Lev Walkin4533a5f2005-03-18 04:22:41 +0000136 RET2RVAL(1, rvalue);
137 }
138 } else if(sameNames) {
139 FATAL("ASN.1 module %s is defined more than once",
Lev Walkinb36317c2005-08-12 10:09:10 +0000140 omod->ModuleName);
Lev Walkin4533a5f2005-03-18 04:22:41 +0000141 RET2RVAL(-1, rvalue);
142 }
143 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000144
Lev Walkinb45e0672004-08-18 05:42:05 +0000145 switch((arg->mod->module_flags & MSF_MASK_TAGS)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000146 case MSF_NOFLAGS:
147 case MSF_EXPLICIT_TAGS:
148 case MSF_IMPLICIT_TAGS:
149 case MSF_AUTOMATIC_TAGS:
150 break;
151 default:
152 FATAL("Module %s defined with ambiguous global tagging mode",
Lev Walkinb36317c2005-08-12 10:09:10 +0000153 arg->mod->ModuleName);
Lev Walkinf15320b2004-06-03 03:38:44 +0000154 RET2RVAL(-1, rvalue);
155 }
156
Lev Walkinb45e0672004-08-18 05:42:05 +0000157 switch((arg->mod->module_flags & MSF_MASK_INSTRUCTIONS)) {
158 case MSF_NOFLAGS:
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000159 /*
160 * arg->mod->module_flags |= MSF_TAG_INSTRUCTIONS;
161 */
Lev Walkinb45e0672004-08-18 05:42:05 +0000162 break;
163 case MSF_unk_INSTRUCTIONS:
164 WARNING("Module %s defined with unrecognized "
Lev Walkinb36317c2005-08-12 10:09:10 +0000165 "encoding reference", arg->mod->ModuleName);
Lev Walkinb45e0672004-08-18 05:42:05 +0000166 RET2RVAL(1, rvalue);
167 /* Fall through */
168 case MSF_TAG_INSTRUCTIONS:
169 case MSF_XER_INSTRUCTIONS:
170 break;
171 default:
172 FATAL("Module %s defined with ambiguous encoding reference",
Lev Walkinb36317c2005-08-12 10:09:10 +0000173 arg->mod->ModuleName);
Lev Walkinb45e0672004-08-18 05:42:05 +0000174 RET2RVAL(-1, rvalue);
175 }
176
Lev Walkinf15320b2004-06-03 03:38:44 +0000177 /*
178 * Do various non-recursive transformations.
Lev Walkinf15320b2004-06-03 03:38:44 +0000179 */
180 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000181 arg->expr = expr;
182
Lev Walkinf593f102005-02-22 07:59:59 +0000183 /* Check whether this type is a duplicate */
184 ret = asn1f_check_duplicate(arg);
185 RET2RVAL(ret, rvalue);
186
Lev Walkinf15320b2004-06-03 03:38:44 +0000187 if(expr->meta_type == AMT_PARAMTYPE)
188 /* Do not process the parametrized type just yet */
189 continue;
190
191 DEBUG("=== Now processing \"%s\" at line %d ===",
192 expr->Identifier, expr->_lineno);
193 assert(expr->meta_type != AMT_INVALID);
194
195 /*
196 * 2.1 Pre-process simple types (ENUMERATED, INTEGER, etc).
197 */
198 ret = asn1f_recurse_expr(arg, asn1f_fix_simple);
199 RET2RVAL(ret, rvalue);
200
201 /*
Lev Walkinf15320b2004-06-03 03:38:44 +0000202 * 2.5.4
203 */
204 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_types);
205 RET2RVAL(ret, rvalue);
206
207 /*
Lev Walkind541c252004-09-05 10:36:22 +0000208 * Fix tagging of top-level types.
209 */
210 ret = asn1f_fix_constr_tag(arg, 1);
211 RET2RVAL(ret, rvalue);
212
213 /*
214 * 2.[234] Process SEQUENCE/SET/CHOICE types.
215 */
216 ret = asn1f_recurse_expr(arg, asn1f_fix_constructed);
217 RET2RVAL(ret, rvalue);
218
219 /*
Lev Walkinf15320b2004-06-03 03:38:44 +0000220 * 2.5.5
221 */
222 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_values);
223 RET2RVAL(ret, rvalue);
224
225 /*
Lev Walkinaa7f5302006-03-14 15:53:59 +0000226 * Parse WITH SYNTAX in CLASSes.
227 */
228 ret = asn1f_parse_class_with_syntax(arg);
229
230 /*
Lev Walkinf15320b2004-06-03 03:38:44 +0000231 * Resolve references in constraints.
232 */
Lev Walkin1ef05162004-08-25 00:42:25 +0000233 ret = asn1f_recurse_expr(arg, asn1f_resolve_constraints);
Lev Walkinf15320b2004-06-03 03:38:44 +0000234 RET2RVAL(ret, rvalue);
235
236 /*
237 * 6. INTEGER value processed at 2.5.4.
238 */
239
240 /*
241 * Make sure everybody's behaving well.
242 */
243 assert(arg->expr == expr);
244 }
245
246 /*
247 * 5. Automatic tagging
248 */
249 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000250
251 arg->expr = expr;
252
253 ret = asn1f_recurse_expr(arg, asn1f_fix_constr_autotag);
254 RET2RVAL(ret, rvalue);
255
256 assert(arg->expr == expr);
257 }
258
259 /*
260 * 8. fix BIT STRING
261 * 9. fix spaces in cstrings
262 */
263 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000264 arg->expr = expr;
265
266 ret = asn1f_recurse_expr(arg, asn1f_fix_bit_string);
267 RET2RVAL(ret, rvalue);
268
269 ret = asn1f_recurse_expr(arg, asn1f_fix_cstring);
270 RET2RVAL(ret, rvalue);
271
272 assert(arg->expr == expr);
273 }
274
275 /*
276 * ... Check for tags distinctness.
277 */
278 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000279 arg->expr = expr;
280
281 ret = asn1f_recurse_expr(arg, asn1f_check_constr_tags_distinct);
282 RET2RVAL(ret, rvalue);
283
284 assert(arg->expr == expr);
285 }
286
Lev Walkind24c62d2004-09-15 11:47:23 +0000287 return rvalue;
288}
289
290static int
291asn1f_fix_module__phase_2(arg_t *arg) {
292 asn1p_expr_t *expr;
293 int rvalue = 0;
294 int ret;
295
Lev Walkin1ef05162004-08-25 00:42:25 +0000296 TQ_FOR(expr, &(arg->mod->members), next) {
297 arg->expr = expr;
298
Lev Walkinf593f102005-02-22 07:59:59 +0000299 if(expr->meta_type == AMT_PARAMTYPE)
Lev Walkind541c252004-09-05 10:36:22 +0000300 /* Do not process the parametrized types here */
301 continue;
302
Lev Walkinb25fa062004-09-29 13:17:06 +0000303 /*
Lev Walkin3645c1c2004-10-31 00:11:50 +0000304 * Dereference DEFAULT values.
305 */
306 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_defaults);
307 RET2RVAL(ret, rvalue);
308
309 /*
Lev Walkinb25fa062004-09-29 13:17:06 +0000310 * Check semantic validity of constraints.
311 */
Lev Walkin1ef05162004-08-25 00:42:25 +0000312 ret = asn1f_recurse_expr(arg, asn1f_check_constraints);
313 RET2RVAL(ret, rvalue);
314
Lev Walkin1dec5802005-03-04 09:02:27 +0000315 /*
316 * Uniquely tag each inner type.
317 */
318 asn1f_apply_unique_index(0);
319 ret = asn1f_recurse_expr(arg, asn1f_apply_unique_index);
320 RET2RVAL(ret, rvalue);
321
Lev Walkin1ef05162004-08-25 00:42:25 +0000322 assert(arg->expr == expr);
323 }
324
Lev Walkinf15320b2004-06-03 03:38:44 +0000325 return rvalue;
326}
327
Lev Walkinf15320b2004-06-03 03:38:44 +0000328static int
329asn1f_fix_simple(arg_t *arg) {
330 int rvalue = 0;
331 int ret;
332
333 ret = asn1f_fix_enum(arg);
334 RET2RVAL(ret, rvalue);
335
336 ret = asn1f_fix_integer(arg);
337 RET2RVAL(ret, rvalue);
338
339 return rvalue;
340}
341
342static int
343asn1f_fix_constructed(arg_t *arg) {
344 int rvalue = 0;
345 int ret;
346
347 switch(arg->expr->expr_type) {
348 case ASN_CONSTR_SEQUENCE:
349 case ASN_CONSTR_SET:
350 case ASN_CONSTR_CHOICE:
351 break;
352 default:
353 return 0;
354 }
355
356 /* Check identifier distinctness */
357 ret = asn1f_check_unique_expr(arg, NULL);
358 RET2RVAL(ret, rvalue);
359
360 /* Fix extensibility */
361 ret = asn1f_fix_constr_ext(arg);
362 RET2RVAL(ret, rvalue);
363
364 /* Fix tagging */
Lev Walkind541c252004-09-05 10:36:22 +0000365 ret = asn1f_fix_constr_tag(arg, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000366 RET2RVAL(ret, rvalue);
367
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000368 /* Import COMPONENTS OF stuff */
369 ret = asn1f_pull_components_of(arg);
370 RET2RVAL(ret, rvalue);
371
Lev Walkinf15320b2004-06-03 03:38:44 +0000372 return rvalue;
373}
374
375static int
Lev Walkin1ef05162004-08-25 00:42:25 +0000376asn1f_resolve_constraints(arg_t *arg) {
Lev Walkinb45e0672004-08-18 05:42:05 +0000377 asn1p_expr_t *top_parent;
Lev Walkin5253da42004-08-20 13:25:56 +0000378 asn1p_expr_type_e etype;
Lev Walkinf15320b2004-06-03 03:38:44 +0000379 int rvalue = 0;
380 int ret;
381
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000382 top_parent = asn1f_find_terminal_type(arg, arg->expr);
Lev Walkin5253da42004-08-20 13:25:56 +0000383 if(top_parent)
384 etype = top_parent->expr_type;
385 else etype = A1TC_INVALID;
386
Lev Walkin03850182005-03-10 10:02:50 +0000387 DEBUG("(%s)", arg->expr->Identifier);
Lev Walkind541c252004-09-05 10:36:22 +0000388
Lev Walkin7ec9b4c2005-03-20 12:57:21 +0000389 ret = asn1constraint_resolve(arg, arg->expr->constraints, etype, 0);
Lev Walkinb45e0672004-08-18 05:42:05 +0000390 RET2RVAL(ret, rvalue);
Lev Walkinf15320b2004-06-03 03:38:44 +0000391
Lev Walkin1ef05162004-08-25 00:42:25 +0000392 return rvalue;
393}
394
395static int
396asn1f_check_constraints(arg_t *arg) {
397 static enum asn1p_constraint_type_e test_types[] = {
398 ACT_EL_RANGE, ACT_CT_SIZE, ACT_CT_FROM };
399 asn1p_expr_t *top_parent;
400 asn1cnst_range_t *range;
401 asn1p_expr_type_e etype;
402 unsigned int i;
403 int rvalue = 0;
404 int ret;
405
Lev Walkin03850182005-03-10 10:02:50 +0000406 DEBUG("(%s{%d/%d})",
Lev Walkind541c252004-09-05 10:36:22 +0000407 arg->expr->Identifier,
408 arg->expr->meta_type, arg->expr->expr_type);
409
Lev Walkin1ef05162004-08-25 00:42:25 +0000410 top_parent = asn1f_find_terminal_type(arg, arg->expr);
411 if(!top_parent)
412 return 0;
413 etype = top_parent->expr_type;
414
Lev Walkinb45e0672004-08-18 05:42:05 +0000415 ret = asn1constraint_pullup(arg);
416 RET2RVAL(ret, rvalue);
417
Lev Walkin1ef05162004-08-25 00:42:25 +0000418 for(i = 0; i < sizeof(test_types)/sizeof(test_types[0]); i++) {
419 range = asn1constraint_compute_PER_range(
Lev Walkinb9fa7802004-08-25 02:04:39 +0000420 etype,
Lev Walkin1ef05162004-08-25 00:42:25 +0000421 arg->expr->combined_constraints,
Lev Walkin4b553412005-08-14 14:45:44 +0000422 test_types[i], 0, 0,
423 CPR_noflags /* ignore -fbless-SIZE */);
Lev Walkind541c252004-09-05 10:36:22 +0000424 if(!range && errno == EPERM) {
Lev Walkin9288d1c2005-03-10 11:27:13 +0000425 FATAL("This error happened for \"%s\" (meta %d) "
426 "at line %d",
Lev Walkind541c252004-09-05 10:36:22 +0000427 arg->expr->Identifier,
428 arg->expr->meta_type,
429 arg->expr->_lineno);
Lev Walkin1ef05162004-08-25 00:42:25 +0000430 return -1;
Lev Walkind541c252004-09-05 10:36:22 +0000431 }
Lev Walkin1ef05162004-08-25 00:42:25 +0000432 asn1constraint_range_free(range);
Lev Walkinb45e0672004-08-18 05:42:05 +0000433 }
Lev Walkin1ef05162004-08-25 00:42:25 +0000434
Lev Walkinf15320b2004-06-03 03:38:44 +0000435 return rvalue;
436}
437
Lev Walkinf593f102005-02-22 07:59:59 +0000438static int
439asn1f_check_duplicate(arg_t *arg) {
440 arg_t tmparg = *arg;
Lev Walkin9c2285a2006-03-09 08:49:26 +0000441 int rvalue = 0;
Lev Walkinf593f102005-02-22 07:59:59 +0000442
443 /*
444 * This is a linear scan in search of a similar type.
445 * The linear scan is just fine for the task, no need to over-optimize.
446 */
447 TQ_FOR(tmparg.mod, &arg->asn->modules, mod_next) {
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000448 int critical = 1; /* FATAL */
449
450 if((arg->mod->_tags & MT_STANDARD_MODULE)
451 != (tmparg.mod->_tags & MT_STANDARD_MODULE)) {
452 /* Ignore clashes with standard module */
453 critical = 0; /* WARNING */
454 }
455
Lev Walkinf593f102005-02-22 07:59:59 +0000456 TQ_FOR(tmparg.expr, &(tmparg.mod->members), next) {
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000457 int diff_files; /* different files */
458
Lev Walkinf593f102005-02-22 07:59:59 +0000459 assert(tmparg.expr->Identifier);
460 assert(arg->expr->Identifier);
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000461
Lev Walkinf593f102005-02-22 07:59:59 +0000462 if(tmparg.expr == arg->expr) break;
463
464 if(strcmp(tmparg.expr->Identifier,
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000465 arg->expr->Identifier))
466 continue;
467
468 diff_files = strcmp(arg->mod->source_file_name,
469 tmparg.mod->source_file_name) ? 1 : 0;
470
471 LOG(critical,
472 "ASN.1 expression \"%s\" at line %d of module %s\n"
473 "clashes with expression \"%s\" at line %d of module %s"
474 "%s%s%s.\n"
475 "Please rename either instance to resolve the conflict",
476 arg->expr->Identifier,
477 arg->expr->_lineno,
478 arg->mod->ModuleName,
479 tmparg.expr->Identifier,
480 tmparg.expr->_lineno,
481 tmparg.mod->ModuleName,
482 diff_files ? " (" : "",
483 diff_files ? tmparg.mod->source_file_name : "",
484 diff_files ? ")" : "");
485 if(critical)
Lev Walkinf593f102005-02-22 07:59:59 +0000486 return -1;
Lev Walkin9c2285a2006-03-09 08:49:26 +0000487 RET2RVAL(1, rvalue);
Lev Walkinf593f102005-02-22 07:59:59 +0000488 }
489 if(tmparg.mod == arg->mod) break;
490 }
491
Lev Walkin9c2285a2006-03-09 08:49:26 +0000492 return rvalue;
Lev Walkinf593f102005-02-22 07:59:59 +0000493}
494
Lev Walkin1dec5802005-03-04 09:02:27 +0000495static int
496asn1f_apply_unique_index(arg_t *arg) {
497 static int unique_index;
498 if(!arg) { unique_index = 0; return 0; }
499
Lev Walkin1dec5802005-03-04 09:02:27 +0000500 arg->expr->_type_unique_index = ++unique_index;
501
502 return 0;
503}
504
Lev Walkinf15320b2004-06-03 03:38:44 +0000505/*
506 * Print everything to stderr
507 */
508static void
509_default_error_logger(int _severity, const char *fmt, ...) {
510 va_list ap;
511 char *pfx = "";
512
513 switch(_severity) {
514 case -1: pfx = "DEBUG: "; break;
515 case 0: pfx = "WARNING: "; break;
516 case 1: pfx = "FATAL: "; break;
517 }
518
519 fprintf(stderr, "%s", pfx);
520 va_start(ap, fmt);
521 vfprintf(stderr, fmt, ap);
522 va_end(ap);
523 fprintf(stderr, "\n");
524}