/pidgin/main: a68f8b2b6873: Always use GRegex in the Debug Window.
Elliott Sales de Andrade
qulogic at pidgin.im
Tue Jul 24 04:03:42 EDT 2012
Changeset: a68f8b2b68735777f1ed6d26c613019d777857cd
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-07-20 01:06 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/a68f8b2b6873
Description:
Always use GRegex in the Debug Window.
Available on Windows, and we require a newer version of GLib than
when this was added, anyway.
diffstat:
config.h.mingw | 3 -
configure.ac | 2 +-
pidgin/gtkdebug.c | 200 +----------------------------------------------------
3 files changed, 5 insertions(+), 200 deletions(-)
diffs (truncated from 447 to 300 lines):
diff --git a/config.h.mingw b/config.h.mingw
--- a/config.h.mingw
+++ b/config.h.mingw
@@ -180,9 +180,6 @@
/* Define to 1 if you have the `random' function. */
/* #define HAVE_RANDOM 1 */
-/* Define to 1 if you have the <regex.h> header file. */
-/* #define HAVE_REGEX_H 1 */
-
/* Define to 1 if you have the `setlocale' function. */
#define HAVE_SETLOCALE 1
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -123,7 +123,7 @@
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(arpa/nameser_compat.h fcntl.h sys/time.h unistd.h locale.h signal.h stdint.h regex.h)
+AC_CHECK_HEADERS(arpa/nameser_compat.h fcntl.h sys/time.h unistd.h locale.h signal.h stdint.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
diff --git a/pidgin/gtkdebug.c b/pidgin/gtkdebug.c
--- a/pidgin/gtkdebug.c
+++ b/pidgin/gtkdebug.c
@@ -37,43 +37,24 @@
#include "gtkutils.h"
#include "pidginstock.h"
-#ifdef HAVE_REGEX_H
-# include <regex.h>
-# define USE_REGEX 1
-#else
-#if GLIB_CHECK_VERSION(2,14,0)
-# define USE_REGEX 1
-#endif
-#endif /* HAVE_REGEX_H */
-
#include <gdk/gdkkeysyms.h>
typedef struct
{
GtkWidget *window;
GtkWidget *text;
+ GtkWidget *filter;
+ GtkWidget *expression;
+ GtkWidget *filterlevel;
GtkListStore *store;
gboolean paused;
-#ifdef USE_REGEX
- GtkWidget *filter;
- GtkWidget *expression;
-
gboolean invert;
gboolean highlight;
-
guint timer;
-# ifdef HAVE_REGEX_H
- regex_t regex;
-# else
GRegex *regex;
-# endif /* HAVE_REGEX_H */
-#else
- GtkWidget *find;
-#endif /* USE_REGEX */
- GtkWidget *filterlevel;
} DebugWindow;
static const char debug_fg_colors[][8] = {
@@ -88,17 +69,14 @@
static DebugWindow *debug_win = NULL;
static guint debug_enabled_timer = 0;
-#ifdef USE_REGEX
static void regex_filter_all(DebugWindow *win);
static void regex_show_all(DebugWindow *win);
-#endif /* USE_REGEX */
static gint
debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused)
{
purple_prefs_disconnect_by_handle(pidgin_debug_get_handle());
-#ifdef USE_REGEX
if(debug_win->timer != 0) {
const gchar *text;
@@ -107,12 +85,7 @@
text = gtk_entry_get_text(GTK_ENTRY(debug_win->expression));
purple_prefs_set_string(PIDGIN_PREFS_ROOT "/debug/regex", text);
}
-#ifdef HAVE_REGEX_H
- regfree(&debug_win->regex);
-#else
g_regex_unref(debug_win->regex);
-#endif /* HAVE_REGEX_H */
-#endif /* USE_REGEX */
/* If the "Save Log" dialog is open then close it */
purple_request_close_with_handle(debug_win);
@@ -140,91 +113,6 @@
return FALSE;
}
-#ifndef USE_REGEX
-struct _find {
- DebugWindow *window;
- GtkWidget *entry;
-};
-
-static void
-do_find_cb(GtkWidget *widget, gint response, struct _find *f)
-{
- switch (response) {
- case GTK_RESPONSE_OK:
- gtk_imhtml_search_find(GTK_IMHTML(f->window->text),
- gtk_entry_get_text(GTK_ENTRY(f->entry)));
- break;
-
- case GTK_RESPONSE_DELETE_EVENT:
- case GTK_RESPONSE_CLOSE:
- gtk_imhtml_search_clear(GTK_IMHTML(f->window->text));
- gtk_widget_destroy(f->window->find);
- f->window->find = NULL;
- g_free(f);
- break;
- }
-}
-
-static void
-find_cb(GtkWidget *w, DebugWindow *win)
-{
- GtkWidget *hbox, *img, *label;
- struct _find *f;
-
- if(win->find)
- {
- gtk_window_present(GTK_WINDOW(win->find));
- return;
- }
-
- f = g_malloc(sizeof(struct _find));
- f->window = win;
- win->find = gtk_dialog_new_with_buttons(_("Find"),
- GTK_WINDOW(win->window), GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL);
- gtk_dialog_set_default_response(GTK_DIALOG(win->find),
- GTK_RESPONSE_OK);
- g_signal_connect(G_OBJECT(win->find), "response",
- G_CALLBACK(do_find_cb), f);
-
- gtk_container_set_border_width(GTK_CONTAINER(win->find), PIDGIN_HIG_BOX_SPACE);
- gtk_window_set_resizable(GTK_WINDOW(win->find), FALSE);
-#if !GTK_CHECK_VERSION(2,22,0)
- gtk_dialog_set_has_separator(GTK_DIALOG(win->find), FALSE);
-#endif
- gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(win->find)->vbox), PIDGIN_HIG_BORDER);
- gtk_container_set_border_width(
- GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), PIDGIN_HIG_BOX_SPACE);
-
- hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
- gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win->find)->vbox),
- hbox);
- img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
- gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
- gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
-
- gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
- gtk_dialog_set_response_sensitive(GTK_DIALOG(win->find),
- GTK_RESPONSE_OK, FALSE);
-
- label = gtk_label_new(NULL);
- gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:"));
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
- f->entry = gtk_entry_new();
- gtk_entry_set_activates_default(GTK_ENTRY(f->entry), TRUE);
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(f->entry));
- g_signal_connect(G_OBJECT(f->entry), "changed",
- G_CALLBACK(pidgin_set_sensitive_if_input),
- win->find);
- gtk_box_pack_start(GTK_BOX(hbox), f->entry, FALSE, FALSE, 0);
-
- gtk_widget_show_all(win->find);
- gtk_widget_grab_focus(f->entry);
-}
-#endif /* USE_REGEX */
-
static void
save_writefile_cb(void *user_data, const char *filename)
{
@@ -259,9 +147,7 @@
{
gtk_imhtml_clear(GTK_IMHTML(win->text));
-#ifdef USE_REGEX
gtk_list_store_clear(win->store);
-#endif /* USE_REGEX */
}
static void
@@ -269,20 +155,17 @@
{
win->paused = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(w));
-#ifdef USE_REGEX
if(!win->paused) {
if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(win->filter)))
regex_filter_all(win);
else
regex_show_all(win);
}
-#endif /* USE_REGEX */
}
/******************************************************************************
* regex stuff
*****************************************************************************/
-#ifdef USE_REGEX
static void
regex_clear_color(GtkWidget *w) {
gtk_widget_modify_base(w, GTK_STATE_NORMAL, NULL);
@@ -312,13 +195,7 @@
static void
regex_match(DebugWindow *win, const gchar *text) {
GtkIMHtml *imhtml = GTK_IMHTML(win->text);
-#ifdef HAVE_REGEX_H
- regmatch_t matches[4]; /* adjust if necessary */
- size_t n_matches = sizeof(matches) / sizeof(matches[0]);
- gint inverted;
-#else
GMatchInfo *match_info;
-#endif /* HAVE_REGEX_H */
gchar *plaintext;
if(!text)
@@ -332,12 +209,7 @@
/* we do a first pass to see if it matches at all. If it does we append
* it, and work out the offsets to highlight.
*/
-#ifdef HAVE_REGEX_H
- inverted = (win->invert) ? REG_NOMATCH : 0;
- if(regexec(&win->regex, plaintext, n_matches, matches, 0) == inverted) {
-#else
if(g_regex_match(win->regex, plaintext, 0, &match_info) != win->invert) {
-#endif /* HAVE_REGEX_H */
gchar *p = plaintext;
GtkTextIter ins;
gint i, offset = 0;
@@ -353,39 +225,13 @@
*/
if(!win->highlight || win->invert) {
g_free(plaintext);
-#ifndef HAVE_REGEX_H
g_match_info_free(match_info);
-#endif
return;
}
/* we use a do-while to highlight the first match, and then continue
* if necessary...
*/
-#ifdef HAVE_REGEX_H
- do {
- size_t m;
-
- for(m = 0; m < n_matches; m++) {
- GtkTextIter ms, me;
-
- if(matches[m].rm_eo == -1)
- break;
-
- i += offset;
-
- gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ms,
- i + matches[m].rm_so);
- gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &me,
- i + matches[m].rm_eo);
- gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "regex",
- &ms, &me);
- offset = matches[m].rm_eo;
- }
-
- p += offset;
- } while(regexec(&win->regex, p, n_matches, matches, REG_NOTBOL) == inverted);
-#else
do
{
gint m;
@@ -419,7 +265,6 @@
i += offset;
} while (g_regex_match(win->regex, p, G_REGEX_MATCH_NOTBOL, &match_info) != win->invert);
g_match_info_free(match_info);
More information about the Commits
mailing list