Put some diagnostic functions into a separate file.
[cparser] / diagnostic.c
1 #include <stdarg.h>
2 #include <stdio.h>
3
4 #include "diagnostic.h"
5
6
7 void parser_print_prefix_pos(const source_position_t pos)
8 {
9         fprintf(stderr, "%s:%u: ", pos.input_name, pos.linenr);
10 }
11
12 void parser_print_warning_prefix_pos(const source_position_t pos)
13 {
14         parser_print_prefix_pos(pos);
15         fputs("warning: ", stderr);
16 }
17
18 void parse_warning_pos(const source_position_t pos, const char *const message)
19 {
20         parser_print_prefix_pos(pos);
21         fprintf(stderr, "warning: %s\n", message);
22 }
23
24 void parse_warning_posf(const source_position_t pos, const char *const fmt, ...)
25 {
26         parser_print_prefix_pos(pos);
27         fputs("warning: ", stderr);
28         va_list ap;
29         va_start(ap, fmt);
30         vfprintf(stderr, fmt, ap);
31         va_end(ap);
32         fputc('\n', stderr);
33 }