From 51f7bb846d519906332efefc09d83ee0f28a98d3 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Thu, 2 Nov 2006 02:09:24 -0600 Subject: [PATCH] Made filters eat error messages without filename --- moo/mooedit/filters.cfg | 8 +++- moo/mooedit/moocommand-exe-unix.c | 13 +++++- moo/mooedit/moocommand.h | 4 +- moo/mooedit/moooutputfilter.c | 47 +++++++++++++++----- moo/mooedit/moooutputfilter.h | 5 ++- moo/mooedit/moooutputfiltersimple.c | 67 +++++++++++++++-------------- 6 files changed, 94 insertions(+), 50 deletions(-) diff --git a/moo/mooedit/filters.cfg b/moo/mooedit/filters.cfg index 32a1edfe..f36f6869 100644 --- a/moo/mooedit/filters.cfg +++ b/moo/mooedit/filters.cfg @@ -1,9 +1,13 @@ [filter] id = bison name = Bison -patterns = /(?P[^:]+):(?P\d+)\.(\d+|\d+\-\d+):/ stderr + e/(?P[^:]+):(?P\d+)\.(\d+|\d+\-\d+):/ [filter] id = latex name = LaTeX -patterns = /^l\.(?P\d+)/ + o/^l\.(?P\d+)/ + o/^LaTeX Warning: Reference .* on page .* undefined on input line (?P\d+)\./ + o/^\! LaTeX Error: .*/ + o/^Overfull \\[vh]box .* detected at line (?P\d+)/ + o/^Overfull \\[vh]box .* in paragraph at lines (?P\d+)/ diff --git a/moo/mooedit/moocommand-exe-unix.c b/moo/mooedit/moocommand-exe-unix.c index d33eeb7a..c4a47b42 100644 --- a/moo/mooedit/moocommand-exe-unix.c +++ b/moo/mooedit/moocommand-exe-unix.c @@ -225,7 +225,7 @@ run_in_pane (MooCommandExe *cmd, /* XXX */ if (!moo_cmd_view_running (MOO_CMD_VIEW (output))) { - MooOutputFilter *filter; + MooOutputFilter *filter = NULL; cmd_line = make_cmd (cmd, ctx); g_return_if_fail (cmd_line != NULL); @@ -234,7 +234,15 @@ run_in_pane (MooCommandExe *cmd, moo_edit_window_present_output (window); gtk_widget_grab_focus (output); - filter = cmd->priv->filter ? moo_command_filter_create (cmd->priv->filter) : NULL; + if (cmd->priv->filter) + filter = moo_command_filter_create (cmd->priv->filter); + + if (filter) + { + const char *fn = MOO_IS_EDIT (doc) ? moo_edit_get_filename (MOO_EDIT (doc)) : NULL; + moo_output_filter_set_active_file (filter, fn); + } + moo_cmd_view_set_filter (MOO_CMD_VIEW (output), filter); moo_cmd_view_run_command_full (MOO_CMD_VIEW (output), @@ -243,6 +251,7 @@ run_in_pane (MooCommandExe *cmd, if (filter) g_object_unref (filter); + g_free (cmd_line); } } diff --git a/moo/mooedit/moocommand.h b/moo/mooedit/moocommand.h index fb5c7dda..a0405f43 100644 --- a/moo/mooedit/moocommand.h +++ b/moo/mooedit/moocommand.h @@ -165,10 +165,10 @@ MooCommandContext *moo_command_context_new (gpointer doc, void moo_command_context_set_doc (MooCommandContext *ctx, gpointer doc); -void moo_command_context_set_window (MooCommandContext *ctx, +void moo_command_context_set_window (MooCommandContext *ctx, gpointer window); gpointer moo_command_context_get_doc (MooCommandContext *ctx); -gpointer moo_command_context_get_window (MooCommandContext *ctx); +gpointer moo_command_context_get_window (MooCommandContext *ctx); void moo_command_context_set (MooCommandContext *ctx, const char *name, diff --git a/moo/mooedit/moooutputfilter.c b/moo/mooedit/moooutputfilter.c index fb0f6b9d..03cec0bc 100644 --- a/moo/mooedit/moooutputfilter.c +++ b/moo/mooedit/moooutputfilter.c @@ -21,6 +21,7 @@ struct _MooOutputFilterPrivate { MooLineView *view; char *working_dir; + char *filename; MooEditWindow *window; }; @@ -44,6 +45,7 @@ moo_output_filter_finalize (GObject *object) MooOutputFilter *filter = MOO_OUTPUT_FILTER (object); g_free (filter->priv->working_dir); + g_free (filter->priv->filename); G_OBJECT_CLASS (moo_output_filter_parent_class)->finalize (object); } @@ -59,7 +61,7 @@ moo_output_filter_activate (MooOutputFilter *filter, if (data) { - moo_output_filter_open_file (filter, data); + moo_output_filter_open_file_line (filter, data); moo_file_line_data_free (data); } } @@ -268,10 +270,8 @@ moo_file_line_data_new (const char *file, { MooFileLineData *data; - g_return_val_if_fail (file != NULL, NULL); - data = g_new0 (MooFileLineData, 1); - data->file = g_strdup (file); + data->file = file && file[0] ? g_strdup (file) : NULL; data->line = line; data->character = character; @@ -305,6 +305,28 @@ moo_file_line_data_free (MooFileLineData *data) } +const char * +moo_output_filter_get_active_file (MooOutputFilter *filter) +{ + g_return_val_if_fail (MOO_IS_OUTPUT_FILTER (filter), NULL); + return filter->priv->filename; +} + + +void +moo_output_filter_set_active_file (MooOutputFilter *filter, + const char *filename) +{ + char *tmp; + + g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter)); + + tmp = filter->priv->filename; + filter->priv->filename = g_strdup (filename); + g_free (tmp); +} + + const char * moo_output_filter_get_working_dir (MooOutputFilter *filter) { @@ -331,23 +353,26 @@ moo_output_filter_get_window (MooOutputFilter *filter) void -moo_output_filter_open_file (MooOutputFilter *filter, - MooFileLineData *data) +moo_output_filter_open_file_line (MooOutputFilter *filter, + MooFileLineData *data) { + const char *filename; const char *path = NULL; char *freeme = NULL; g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter)); g_return_if_fail (data != NULL); - g_return_if_fail (data->file != NULL); - if (g_path_is_absolute (data->file)) + filename = data->file ? data->file : filter->priv->filename; + g_return_if_fail (filename != NULL); + + if (g_path_is_absolute (filename)) { - path = data->file; + path = filename; } else if (filter->priv->working_dir) { - freeme = g_build_filename (filter->priv->working_dir, data->file, NULL); + freeme = g_build_filename (filter->priv->working_dir, filename, NULL); path = freeme; } @@ -365,7 +390,7 @@ moo_output_filter_open_file (MooOutputFilter *filter, } else { - _moo_message ("could not find file '%s'", data->file); + _moo_message ("could not find file '%s'", filename); } g_free (freeme); diff --git a/moo/mooedit/moooutputfilter.h b/moo/mooedit/moooutputfilter.h index 093cbf38..4656153f 100644 --- a/moo/mooedit/moooutputfilter.h +++ b/moo/mooedit/moooutputfilter.h @@ -87,12 +87,15 @@ void moo_output_filter_cmd_start (MooOutputFilter *filter, gboolean moo_output_filter_cmd_exit (MooOutputFilter *filter, int status); +const char *moo_output_filter_get_active_file (MooOutputFilter *filter); +void moo_output_filter_set_active_file (MooOutputFilter *filter, + const char *filename); const char *moo_output_filter_get_working_dir (MooOutputFilter *filter); void moo_output_filter_set_window (MooOutputFilter *filter, gpointer window); gpointer moo_output_filter_get_window (MooOutputFilter *filter); -void moo_output_filter_open_file (MooOutputFilter *filter, +void moo_output_filter_open_file_line (MooOutputFilter *filter, MooFileLineData *data); diff --git a/moo/mooedit/moooutputfiltersimple.c b/moo/mooedit/moooutputfiltersimple.c index a0f6317e..6d717253 100644 --- a/moo/mooedit/moooutputfiltersimple.c +++ b/moo/mooedit/moooutputfiltersimple.c @@ -27,7 +27,6 @@ #define KEY_BUILTIN "builtin" #define KEY_NAME "name" #define KEY_ENABLED "enabled" -#define KEY_PATTERNS "patterns" typedef struct { @@ -103,7 +102,10 @@ parse_file_line (const char *file, { MooFileLineData *data; - if (!file || !file[0]) + file = file && *file ? file : NULL; + line = line && *line ? line : NULL; + + if (!file && !line) return NULL; data = moo_file_line_data_new (file, -1, -1); @@ -116,7 +118,6 @@ parse_file_line (const char *file, static void process_result (const char *text, EggRegex *regex, - MooOutputTextType type, MooLineView *view) { char *file, *line, *character; @@ -128,8 +129,7 @@ process_result (const char *text, line = egg_regex_fetch_named (regex, "line", text); character = egg_regex_fetch_named (regex, "character", text); - tag = moo_line_view_lookup_tag (view, type == MOO_OUTPUT_STDOUT ? - MOO_CMD_VIEW_STDOUT : MOO_CMD_VIEW_STDERR); + tag = moo_line_view_lookup_tag (view, MOO_CMD_VIEW_STDERR); line_no = moo_line_view_write_line (view, text, -1, tag); data = parse_file_line (file, line, character); @@ -164,8 +164,7 @@ process_line (MooOutputFilterSimple *filter, if (!egg_regex_match (regex->re, text, 0)) continue; - process_result (text, regex->re, type, - moo_output_filter_get_view (MOO_OUTPUT_FILTER(filter))); + process_result (text, regex->re, moo_output_filter_get_view (MOO_OUTPUT_FILTER(filter))); return TRUE; } @@ -440,9 +439,6 @@ _moo_output_filter_info_unref (MooOutputFilterInfo *info) /* Loading and saving */ -#define CHAR_IS_SPACE(c) ((c) == ' ' || (c) == '\t') -#define CHAR_IS_SEPARATOR(c) ((c) == ',' || (c) == ';') - static gboolean parse_patterns (MooOutputFilterInfo *info, const char *string, @@ -463,13 +459,37 @@ parse_patterns (MooOutputFilterInfo *info, gunichar delim; char *pattern_start, *pattern_end; MooOutputPatternInfo *pattern_info; + MooOutputTextType type; - while (*string && CHAR_IS_SPACE (*string)) - string++; + while (*string) + { + gunichar c = g_utf8_get_char (string); + + if (c != ',' && c != ';' && !g_unichar_isspace (c)) + break; + + string = g_utf8_next_char (string); + } if (!*string) break; + switch (*string++) + { + case 'o': + type = MOO_OUTPUT_STDOUT; + break; + case 'e': + type = MOO_OUTPUT_STDERR; + break; + case 'a': + type = MOO_OUTPUT_ALL; + break; + default: + g_warning ("output type missing: '%s'", string - 1); + goto error; + } + delim = g_utf8_get_char (string); pattern_start = g_utf8_next_char (string); pattern_end = g_utf8_strchr (pattern_start, -1, delim); @@ -482,27 +502,10 @@ parse_patterns (MooOutputFilterInfo *info, pattern_info = g_new0 (MooOutputPatternInfo, 1); pattern_info->pattern = g_strndup (pattern_start, pattern_end - pattern_start); - pattern_info->type = MOO_OUTPUT_ALL; + pattern_info->type = type; patterns = g_slist_prepend (patterns, pattern_info); string = g_utf8_next_char (pattern_end); - - while (*string && CHAR_IS_SPACE (*string)) - string++; - - if (!strncmp (string, "stdout", strlen ("stdout"))) - { - pattern_info->type = MOO_OUTPUT_STDOUT; - string += strlen ("stdout"); - } - else if (!strncmp (string, "stderr", strlen ("stderr"))) - { - pattern_info->type = MOO_OUTPUT_STDERR; - string += strlen ("stderr"); - } - - if (CHAR_IS_SEPARATOR (*string)) - string++; } info->n_patterns = g_slist_length (patterns); @@ -556,12 +559,12 @@ parse_item (MooKeyFileItem *item, if (info->deleted || info->builtin) return info; - pattern_string = moo_key_file_item_steal (item, KEY_PATTERNS); + pattern_string = moo_key_file_item_steal_content (item); if (!parse_patterns (info, pattern_string, file)) { _moo_output_filter_info_unref (info); - return NULL; + info = NULL; } g_free (pattern_string);