[alleyoop] Switched to using GRegex
- From: Jeffrey Stedfast <fejj src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [alleyoop] Switched to using GRegex
- Date: Wed, 25 Nov 2009 04:11:46 +0000 (UTC)
commit 22121ab2fc9be59cc7cbb4a7eb800e7cadc7101c
Author: Jeffrey Stedfast <fejj gnome org>
Date: Tue Nov 24 23:09:57 2009 -0500
Switched to using GRegex
2009-11-24 Jeffrey Stedfast <fejj novell com>
* configure.in: We now require glib-2.0 >= 2.14 for GRegex.
* src/vgdefaultview.c: Switched to using GRegex which gives us
much nicer error messages when regex patterns fail to
compile. Plus the GRegex API is a bit nicer to work with.
ChangeLog | 8 +++++++
TODO | 2 -
configure.in | 2 +-
src/vgdefaultview.c | 51 ++++++++++++++++++++++++++++---------------------
src/vgdefaultview.h | 3 +-
src/vggeneralprefs.c | 2 +-
6 files changed, 40 insertions(+), 28 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 55599aa..28e18a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-11-24 Jeffrey Stedfast <fejj novell com>
+
+ * configure.in: We now require glib-2.0 >= 2.14 for GRegex.
+
+ * src/vgdefaultview.c: Switched to using GRegex which gives us
+ much nicer error messages when regex patterns fail to
+ compile. Plus the GRegex API is a bit nicer to work with.
+
2009-11-23 Jeffrey Stedfast <fejj novell com>
* configure.in: Bumped version to 0.9.7
diff --git a/TODO b/TODO
index 3efb771..90dec47 100644
--- a/TODO
+++ b/TODO
@@ -3,8 +3,6 @@ TODO List
* When searching, highlight the part of the error that matches the search
-* Switch to using GRegex
-
* Add tooltips for config options and other places
* Might want to consider using the XML format from valgrind
diff --git a/configure.in b/configure.in
index d53ba4f..b203f0e 100644
--- a/configure.in
+++ b/configure.in
@@ -78,7 +78,7 @@ if test "x$enable_vgstrpool" = "xyes"; then
AC_DEFINE(ENABLE_STRPOOL,1,[Enable the use of vgstrpool.c (an attempt at keeping memory usage down).])
fi
-PKG_CHECK_MODULES(PACKAGE, glib-2.0 gtk+-2.0 libglade-2.0 libgnomeui-2.0 gconf-2.0)
+PKG_CHECK_MODULES(PACKAGE, glib-2.0 >= 2.14 gtk+-2.0 libglade-2.0 libgnomeui-2.0 gconf-2.0)
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
diff --git a/src/vgdefaultview.c b/src/vgdefaultview.c
index a3628fe..3f154ce 100644
--- a/src/vgdefaultview.c
+++ b/src/vgdefaultview.c
@@ -188,28 +188,33 @@ static void
set_search (VgDefaultView *view, int item_id, const char *expr)
{
GtkWidget *parent, *dialog;
- size_t size;
- char *err;
- int ret;
+ GError *err = NULL;
- if (view->search_id != SEARCH_ID_NONE)
- regfree (&view->search_regex);
+ if (view->search_regex != NULL) {
+ g_regex_unref (view->search_regex);
+ view->search_regex = NULL;
+ }
view->search_id = item_id;
if (item_id == SEARCH_ID_NONE)
return;
- if ((ret = regcomp (&view->search_regex, expr, REG_EXTENDED | REG_NOSUB)) == 0)
+#define COMPILE_FLAGS (G_REGEX_CASELESS | G_REGEX_EXTENDED | G_REGEX_OPTIMIZE)
+ view->search_regex = g_regex_new (expr, COMPILE_FLAGS, 0, &err);
+#undef COMPILE_FLAGS
+
+ if (err == NULL) {
+ /* all is good in the world... */
return;
+ }
/* regex compilation failed */
view->search_id = SEARCH_ID_NONE;
- size = regerror (ret, &view->search_regex, NULL, 0);
- err = g_malloc (size);
- regerror (ret, &view->search_regex, err, size);
-
- regfree (&view->search_regex);
+ if (view->search_regex != NULL) {
+ g_regex_unref (view->search_regex);
+ view->search_regex = NULL;
+ }
parent = gtk_widget_get_toplevel ((GtkWidget *) view);
parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
@@ -217,9 +222,8 @@ set_search (VgDefaultView *view, int item_id, const char *expr)
dialog = gtk_message_dialog_new ((GtkWindow *) parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- _("Invalid regular expression: '%s': %s"),
- expr, err);
- g_free (err);
+ "%s", err->message);
+ g_error_free (err);
gtk_dialog_run ((GtkDialog *) dialog);
gtk_widget_destroy (dialog);
@@ -253,6 +257,7 @@ vg_default_view_init (VgDefaultView *view)
view->suppressions = g_ptr_array_new ();
view->errors = g_ptr_array_new ();
view->search_id = SEARCH_ID_NONE;
+ view->search_regex = NULL;
view->parser = NULL;
view->rules_id = 0;
view->srclines = 0;
@@ -311,8 +316,10 @@ vg_default_view_finalize (GObject *obj)
view->parser = NULL;
}
- if (view->search_id != SEARCH_ID_NONE)
- regfree (&view->search_regex);
+ if (view->search_regex != NULL) {
+ g_regex_unref (view->search_regex);
+ view->search_regex = NULL;
+ }
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
@@ -423,7 +430,7 @@ view_show_error (VgDefaultView *view, GtkTreeStore *model, VgError *err)
if (stack->type != VG_STACK_EMPTY) {
g_string_append (str, " [");
-
+
if (stack->type == VG_STACK_SOURCE) {
if (stack->info.src.filename) {
g_string_append (str, stack->info.src.filename);
@@ -472,7 +479,7 @@ view_show_error (VgDefaultView *view, GtkTreeStore *model, VgError *err)
}
static gboolean
-error_matches_search (VgError *err, int search_id, regex_t *regex)
+error_matches_search (VgError *err, int search_id, GRegex *regex)
{
VgErrorSummary *summary;
VgErrorStack *stack;
@@ -485,7 +492,7 @@ error_matches_search (VgError *err, int search_id, regex_t *regex)
summary = err->summary;
if (search_id == SEARCH_ID_ERROR) {
- return regexec (regex, summary->report, 0, NULL, 0) == 0;
+ return g_regex_match (regex, summary->report, 0, NULL);
} else {
do {
stack = summary->frames;
@@ -506,7 +513,7 @@ error_matches_search (VgError *err, int search_id, regex_t *regex)
g_assert_not_reached ();
}
- if (str && regexec (regex, str, 0, NULL, 0) == 0)
+ if (str && g_regex_match (regex, str, 0, NULL))
return TRUE;
stack = stack->next;
@@ -532,7 +539,7 @@ view_rebuild (VgDefaultView *view)
for (i = 0; i < view->errors->len; i++) {
VgError *err = view->errors->pdata[i];
- if (error_matches_search (err, view->search_id, &view->search_regex))
+ if (error_matches_search (err, view->search_id, view->search_regex))
view_show_error (view, model, err);
}
}
@@ -557,7 +564,7 @@ recv_error_cb (VgErrorParser *parser, VgError *err, gpointer user_data)
model = (GtkTreeStore *) gtk_tree_view_get_model ((GtkTreeView *) view->table);
- if (error_matches_search (err, view->search_id, &view->search_regex))
+ if (error_matches_search (err, view->search_id, view->search_regex))
view_show_error (view, model, err);
}
diff --git a/src/vgdefaultview.h b/src/vgdefaultview.h
index 23e27ae..4b0b563 100644
--- a/src/vgdefaultview.h
+++ b/src/vgdefaultview.h
@@ -26,7 +26,6 @@
#include <gconf/gconf-client.h>
#include <sys/types.h>
-#include <regex.h>
#include "vgtoolview.h"
#include "vgerror.h"
@@ -59,8 +58,8 @@ struct _VgDefaultView {
GPtrArray *suppressions;
+ GRegex *search_regex;
int search_id;
- regex_t search_regex;
guint rules_id;
diff --git a/src/vggeneralprefs.c b/src/vggeneralprefs.c
index 158b09e..e9d94d2 100644
--- a/src/vggeneralprefs.c
+++ b/src/vggeneralprefs.c
@@ -230,7 +230,7 @@ vg_general_prefs_init (VgGeneralPrefs *prefs)
gtk_box_pack_start ((GtkBox *) vbox, widget, FALSE, FALSE, 0);
bool = gconf_client_get_bool (gconf, TRACK_ORIGINS_KEY, NULL);
- widget = gtk_check_button_new_with_label (_("Track rigins of undefined values"));
+ widget = gtk_check_button_new_with_label (_("Track origins of undefined values"));
g_signal_connect (widget, "toggled", G_CALLBACK (toggle_button_toggled), TRACK_ORIGINS_KEY);
gtk_toggle_button_set_active ((GtkToggleButton *) widget, bool);
prefs->track_origins = (GtkToggleButton *) widget;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]