diff options
Diffstat (limited to 'src/diag.c')
-rw-r--r-- | src/diag.c | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/src/diag.c b/src/diag.c deleted file mode 100644 index 30ffa34..0000000 --- a/src/diag.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* This file is part of Eclat. | ||
2 | Copyright (C) 2012 Sergey Poznyakoff. | ||
3 | |||
4 | Eclat is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Eclat is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "eclat.h" | ||
18 | |||
19 | const char *program_name; | ||
20 | |||
21 | void | ||
22 | vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap) | ||
23 | { | ||
24 | if (program_name) | ||
25 | fprintf(stderr, "%s: ", program_name); | ||
26 | |||
27 | if (locus) { | ||
28 | size_t size = 0; | ||
29 | |||
30 | if (locus->beg.col == 0) | ||
31 | fprintf(stderr, "%s:%u", | ||
32 | locus->beg.file, | ||
33 | locus->beg.line); | ||
34 | else if (strcmp(locus->beg.file, locus->end.file)) | ||
35 | fprintf(stderr, "%s:%u.%u-%s:%u.%u", | ||
36 | locus->beg.file, | ||
37 | locus->beg.line, locus->beg.col, | ||
38 | locus->end.file, | ||
39 | locus->end.line, locus->end.col); | ||
40 | else if (locus->beg.line != locus->end.line) | ||
41 | fprintf(stderr, "%s:%u.%u-%u.%u", | ||
42 | locus->beg.file, | ||
43 | locus->beg.line, locus->beg.col, | ||
44 | locus->end.line, locus->end.col); | ||
45 | else | ||
46 | fprintf(stderr, "%s:%u.%u-%u", | ||
47 | locus->beg.file, | ||
48 | locus->beg.line, locus->beg.col, | ||
49 | locus->end.col); | ||
50 | fprintf(stderr, ": "); | ||
51 | } | ||
52 | |||
53 | if (qual) | ||
54 | fprintf(stderr, "%s: ", qual); | ||
55 | vfprintf(stderr, fmt, ap); | ||
56 | fputc('\n', stderr); | ||
57 | } | ||
58 | |||
59 | void | ||
60 | diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...) | ||
61 | { | ||
62 | va_list ap; | ||
63 | |||
64 | va_start(ap, fmt); | ||
65 | vdiag(locus, qual, fmt, ap); | ||
66 | va_end(ap); | ||
67 | } | ||
68 | |||
69 | void | ||
70 | die(int status, const char *fmt, ...) | ||
71 | { | ||
72 | va_list ap; | ||
73 | |||
74 | va_start(ap, fmt); | ||
75 | vdiag(NULL, NULL, fmt, ap); | ||
76 | va_end(ap); | ||
77 | exit(status); | ||
78 | } | ||
79 | |||
80 | void | ||
81 | err(const char *fmt, ...) | ||
82 | { | ||
83 | va_list ap; | ||
84 | |||
85 | va_start(ap, fmt); | ||
86 | vdiag(NULL, NULL, fmt, ap); | ||
87 | va_end(ap); | ||
88 | } | ||
89 | |||
90 | void | ||
91 | warn(const char *fmt, ...) | ||
92 | { | ||
93 | va_list ap; | ||
94 | |||
95 | va_start(ap, fmt); | ||
96 | vdiag(NULL, "warning", fmt, ap); | ||
97 | va_end(ap); | ||
98 | } | ||
99 | |||
100 | void | ||
101 | debug_printf(const char *fmt, ...) | ||
102 | { | ||
103 | va_list ap; | ||
104 | |||
105 | va_start(ap, fmt); | ||
106 | vdiag(NULL, "debug", fmt, ap); | ||
107 | va_end(ap); | ||
108 | } | ||