- struct category
- {
- bool show_command_name; /* Show command name with error? */
- bool show_file_location; /* Show syntax file location? */
- };
-
- static const struct category categories[] =
- {
- {false, false}, /* MSG_GENERAL. */
- {true, true}, /* MSG_SYNTAX. */
- {false, true}, /* MSG_DATA. */
- };
-
- struct severity
- {
- enum settings_output_type type;
- const char *name; /* How to identify this severity. */
- int *count; /* Number of msgs with this severity so far. */
- };
-
- static struct severity severities[] =
- {
- { SETTINGS_OUTPUT_ERROR, N_("error"), &error_count },
- { SETTINGS_OUTPUT_ERROR, N_("warning"), &warning_count },
- { SETTINGS_OUTPUT_NOTE, NULL, NULL},
- };
-
- const struct category *category = &categories[m->category];
- const struct severity *severity = &severities[m->severity];
- struct string string = DS_EMPTY_INITIALIZER;
- enum settings_output_devices routing;
-
- if (category->show_file_location && m->where.file_name)
- {
- ds_put_format (&string, "%s:", m->where.file_name);
- if (m->where.line_number != -1)
- ds_put_format (&string, "%d:", m->where.line_number);
- ds_put_char (&string, ' ');
- }
-
- if (severity->name != NULL)
- ds_put_format (&string, "%s: ", gettext (severity->name));
-
- if (severity->count != NULL)
- ++*severity->count;
-
- if (category->show_command_name && msg_get_command_name () != NULL)
- ds_put_format (&string, "%s: ", msg_get_command_name ());
-
- ds_put_cstr (&string, m->text);
-
- routing = settings_get_output_routing (severity->type);
- if (msg_file != stdout || routing & SETTINGS_DEVICE_TERMINAL)
- dump_message (ds_cstr (&string),
- isatty (fileno (msg_file)) ? settings_get_viewwidth () : INT_MAX, 8,
- write_stream, msg_file);
-
- dump_message (ds_cstr (&string), 78, 0, write_journal, NULL);
-
- if (routing & SETTINGS_DEVICE_LISTING)
- {
- /* Disable terminal output devices, because the error should already have
- been reported to the terminal with the dump_message call above. */
- settings_set_output_routing (severity->type,
- routing & ~SETTINGS_DEVICE_TERMINAL);
- tab_output_text (TAB_LEFT, ds_cstr (&string));
- settings_set_output_routing (severity->type, routing);
- }
-
- ds_destroy (&string);