Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Forstner, Matyas | |
11 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #include "error.h" |
14 | #include <stdio.h> | |
15 | #include <stdlib.h> | |
16 | #include <stdarg.h> | |
17 | ||
18 | unsigned verb_level=0x0007; /* default value */ | |
19 | ||
20 | const char *argv0; /* the programname :) */ | |
21 | ||
22 | void fatal_error(const char *filename, int lineno, const char *fmt, ...) | |
23 | { | |
24 | va_list parameters; | |
25 | fprintf(stderr, "FATAL ERROR: %s: In line %d of %s: ", | |
26 | argv0, lineno, filename); | |
27 | va_start(parameters, fmt); | |
28 | vfprintf(stderr, fmt, parameters); | |
29 | va_end(parameters); | |
30 | fprintf(stderr, "\n"); | |
31 | fflush(stderr); | |
32 | abort(); | |
33 | } | |
34 | ||
35 | void ERROR(const char *fmt, ...) | |
36 | { | |
37 | fprintf(stderr, "%s: error: ", argv0); | |
38 | va_list parameters; | |
39 | va_start(parameters, fmt); | |
40 | vfprintf(stderr, fmt, parameters); | |
41 | va_end(parameters); | |
42 | fprintf(stderr, "\n"); | |
43 | fflush(stderr); | |
44 | } | |
45 | ||
46 | void WARNING(const char *fmt, ...) | |
47 | { | |
48 | if(!(verb_level & 2)) return; | |
49 | fprintf(stderr, "%s: warning: ", argv0); | |
50 | va_list parameters; | |
51 | va_start(parameters, fmt); | |
52 | vfprintf(stderr, fmt, parameters); | |
53 | va_end(parameters); | |
54 | fprintf(stderr, "\n"); | |
55 | fflush(stderr); | |
56 | } | |
57 | ||
58 | void NOTSUPP(const char *fmt, ...) | |
59 | { | |
60 | if(!(verb_level & 1)) return; | |
61 | fprintf(stderr, "%s: warning: not supported: ", argv0); | |
62 | va_list parameters; | |
63 | va_start(parameters, fmt); | |
64 | vfprintf(stderr, fmt, parameters); | |
65 | va_end(parameters); | |
66 | fprintf(stderr, "\n"); | |
67 | fflush(stderr); | |
68 | } | |
69 | ||
70 | void NOTIFY(const char *fmt, ...) | |
71 | { | |
72 | if(!(verb_level & 4)) return; | |
73 | fprintf(stderr, "Notify: "); | |
74 | va_list parameters; | |
75 | va_start(parameters, fmt); | |
76 | vfprintf(stderr, fmt, parameters); | |
77 | va_end(parameters); | |
78 | fprintf(stderr, "\n"); | |
79 | fflush(stderr); | |
80 | } | |
81 | ||
82 | void DEBUG(unsigned level, const char *fmt, ...) | |
83 | { | |
84 | if((level>7?7:level)>((verb_level>>3)&0x07)) return; | |
85 | fprintf(stderr, "%*sDebug: ", level, ""); | |
86 | va_list parameters; | |
87 | va_start(parameters, fmt); | |
88 | vfprintf(stderr, fmt, parameters); | |
89 | va_end(parameters); | |
90 | fprintf(stderr, "\n"); | |
91 | fflush(stderr); | |
92 | } |