Feature: Show the column number in diagnostic messages.
[cparser] / diagnostic.c
index dd9e43e..782c657 100644 (file)
@@ -34,6 +34,7 @@ unsigned diagnostic_count = 0;
 unsigned error_count      = 0;
 /** Number of occurred warnings. */
 unsigned warning_count    = 0;
+bool     show_column      = true;
 
 static const source_position_t *curr_pos = NULL;
 
@@ -43,6 +44,8 @@ static const source_position_t *curr_pos = NULL;
 static void print_source_position(FILE *out, const source_position_t *pos)
 {
        fprintf(out, "at line %u", pos->lineno);
+       if (show_column)
+               fprintf(out, ":%u", pos->colno);
        if (curr_pos == NULL || curr_pos->input_name != pos->input_name)
                fprintf(out, " of \"%s\"", pos->input_name);
 }
@@ -193,7 +196,10 @@ void diagnosticf(const char *const fmt, ...)
 static void diagnosticposvf(source_position_t const *const pos, char const *const kind, char const *const fmt, va_list ap)
 {
        FILE *const out = stderr;
-       fprintf(out, "%s:%u: %s: ", pos->input_name, pos->lineno, kind);
+       fprintf(out, "%s:%u:", pos->input_name, pos->lineno);
+       if (show_column)
+               fprintf(out, "%u:", pos->colno);
+       fprintf(out, " %s: ", kind);
        curr_pos = pos;
        diagnosticvf(fmt, ap);
        fputc('\n', out);