[pan2] Bug 596653: Use GRegex instead of PCRE
- From: Charles Stephen Kerr <csk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pan2] Bug 596653: Use GRegex instead of PCRE
- Date: Mon, 28 Sep 2009 19:25:23 +0000 (UTC)
commit 80a3b0991cb5c6f1fd20a78a75827a278698117a
Author: Charles Kerr <charles rebelbase com>
Date: Mon Sep 28 14:24:57 2009 -0500
Bug 596653: Use GRegex instead of PCRE
configure.in | 9 +---
pan.spec.in | 2 -
pan/data-impl/Makefile.am | 2 +-
pan/data/Makefile.am | 2 +-
pan/general/Makefile.am | 4 +-
pan/general/text-match.cc | 100 +++++++++++++-----------------------------
pan/gui/Makefile.am | 2 +-
pan/tasks/Makefile.am | 4 +-
pan/usenet-utils/Makefile.am | 2 +-
9 files changed, 41 insertions(+), 86 deletions(-)
---
diff --git a/configure.in b/configure.in
index b0a8c51..8f806f2 100644
--- a/configure.in
+++ b/configure.in
@@ -13,17 +13,15 @@ AM_MAINTAINER_MODE
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
-dnl pcre, glib, gmime, and gtk are manditory prerequisites.
+dnl glib, gmime, and gtk are manditory prerequisites.
dnl
dnl GtkSpell is optional: GTKSPELL_REQUIRED refers to the minimum version
dnl needed if you want to build Pan with spellchecking in the Post window.
-PCRE_REQUIRED=5.0
-GLIB_REQUIRED=2.4.0
+GLIB_REQUIRED=2.14.0
GMIME_REQUIRED=2.1.9
-GTK_REQUIRED=2.4.0
+GTK_REQUIRED=2.12.0
GTKSPELL_REQUIRED=2.0.7
-AC_SUBST(PCRE_REQUIRED)
AC_SUBST(GLIB_REQUIRED)
AC_SUBST(GMIME_REQUIRED)
AC_SUBST(GTK_REQUIRED)
@@ -50,7 +48,6 @@ AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[Gettext package])
AM_GLIB_GNU_GETTEXT
panlocaledir='${prefix}/${DATADIRNAME}/locale'
-PKG_CHECK_MODULES(PCRE, libpcre >= $PCRE_REQUIRED)
AM_PATH_GLIB_2_0($GLIB_REQUIRED,,exit 1,gobject gmodule gthread)
PKG_CHECK_MODULES(GMIME, gmime-2.0 >= $GMIME_REQUIRED)
AM_PATH_GTK_2_0($GTK_REQUIRED,,exit 1,gthread)
diff --git a/pan.spec.in b/pan.spec.in
index f6e5d07..a9c7d5c 100644
--- a/pan.spec.in
+++ b/pan.spec.in
@@ -17,10 +17,8 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: glib2-devel >= @GLIB_REQUIRED@
BuildRequires: gmime-devel >= @GMIME_REQUIRED@
BuildRequires: gtk2-devel >= @GTK_REQUIRED@
-BuildRequires: pcre-devel >= @PCRE_REQUIRED@
%{!?_without_gtkspell:BuildRequires: gtkspell-devel >= @GTKSPELL_REQUIRED }
-Requires: pcre >= @PCRE_REQUIRED@
Requires: glib2 >= @GLIB_REQUIRED@
Requires: gmime >= @GMIME_REQUIRED@
Requires: gtk2 >= @GTK_REQUIRED@
diff --git a/pan/data-impl/Makefile.am b/pan/data-impl/Makefile.am
index 2263501..68340be 100644
--- a/pan/data-impl/Makefile.am
+++ b/pan/data-impl/Makefile.am
@@ -37,7 +37,7 @@ TEST_LDADD = \
../usenet-utils/libusenetutils.a \
../general/libgeneralutils.a \
../../uulib/libuu.a \
- @GMIME_LIBS@ @GLIB_LIBS@ @PCRE_LIBS@
+ @GMIME_LIBS@ @GLIB_LIBS@
add_server_SOURCES = add-server.cc
add_server_LDADD = $(TEST_LDADD)
headers_test_SOURCES = headers-test.cc
diff --git a/pan/data/Makefile.am b/pan/data/Makefile.am
index fec77ff..6ff3ebe 100644
--- a/pan/data/Makefile.am
+++ b/pan/data/Makefile.am
@@ -29,7 +29,7 @@ noinst_PROGRAMS = \
#dnl decode_test_LDADD = $(TEST_LDADD)
TESTS = $(noinst_PROGRAMS)
-TEST_LDADD = ./libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a @GMIME_LIBS@ @GLIB_LIBS@ @PCRE_LIBS@
+TEST_LDADD = ./libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a @GMIME_LIBS@ @GLIB_LIBS@
xref_test_SOURCES = xref-test.cc
xref_test_LDADD = $(TEST_LDADD)
article_test_SOURCES = article-test.cc
diff --git a/pan/general/Makefile.am b/pan/general/Makefile.am
index 59bf4fc..8bfe693 100644
--- a/pan/general/Makefile.am
+++ b/pan/general/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -I top_srcdir@ @GMIME_CFLAGS@ @GLIB_CFLAGS@ @PCRE_CFLAGS@
+AM_CPPFLAGS = -I top_srcdir@ @GMIME_CFLAGS@ @GLIB_CFLAGS@
noinst_LIBRARIES = libgeneralutils.a
@@ -43,7 +43,7 @@ noinst_PROGRAMS = \
text-match-test
TESTS = $(noinst_PROGRAMS)
-TEST_LDADD = ./libgeneralutils.a @GMIME_CFLAGS@ @GLIB_LIBS@ @PCRE_LIBS@
+TEST_LDADD = ./libgeneralutils.a @GMIME_CFLAGS@ @GLIB_LIBS@
progress_test_SOURCES = progress-test.cc
progress_test_LDADD = $(TEST_LDADD)
quark_test_SOURCES = quark-test.cc
diff --git a/pan/general/text-match.cc b/pan/general/text-match.cc
index f1ad145..7c0bdb0 100644
--- a/pan/general/text-match.cc
+++ b/pan/general/text-match.cc
@@ -20,7 +20,6 @@
#include <config.h>
extern "C" {
#include <ctype.h>
- #include <pcre.h>
#include <glib.h>
#include <glib/gi18n.h>
}
@@ -161,36 +160,19 @@ class pan::TextMatch::PcreInfo
{
public:
- int ovector_bufsize;
- int * ovector;
- pcre * re;
- pcre_extra * extra;
+ GRegex * re;
public:
- PcreInfo ():
- ovector_bufsize(0),
- ovector(0),
- re(0),
- extra(0)
- {
- }
+ PcreInfo (): re(0) { }
+
+
-// this is kind of a hack that would (apparently) be solved
-// by building/finding a static libpcre.a for Win32 and linking
-// against that instead of against the pcre dll.
-#ifdef G_OS_WIN32
-#define pcre_free free
-#endif
~PcreInfo ()
{
if (re)
- pcre_free (re);
- if (extra)
- pcre_free (extra);
- if (ovector)
- g_free (ovector);
+ g_regex_unref (re);
}
public:
@@ -198,44 +180,23 @@ class pan::TextMatch::PcreInfo
bool set (const std::string& pattern,
bool case_sensitive)
{
- static int default_options (0);
- static bool checked_pcre_for_utf8_support (false);
- if (!checked_pcre_for_utf8_support) {
- checked_pcre_for_utf8_support = true;
- int i = 0;
- pcre_config (PCRE_CONFIG_UTF8, &i);
- if (i)
- default_options |= PCRE_UTF8;
- else
- Log::add_err (_("Your copy of libpcre doesn't support UTF-8. UTF-8 regular expressions may fail."));
- }
-
- int options = default_options;
- if (!case_sensitive)
- options |= PCRE_CASELESS;
-
- const char *err = 0;
- int err_offset = 0;
- re = pcre_compile (pattern.c_str(), options, &err, &err_offset, NULL);
- if (!re) {
- Log::add_err_va (_("Can't use regular expression \"%s\": %s at position %d"),
- pattern.c_str(), err, err_offset);
- return false;
- }
-
- extra = pcre_study (re, 0, &err);
- if (err) {
- Log::add_err_va (
- _("Can't use regular expression \"%s\": %s"), pattern.c_str(), err);
- return false;
- }
-
- int capturecount = 0;
- pcre_fullinfo (re, extra, PCRE_INFO_CAPTURECOUNT, &capturecount);
- ovector_bufsize = 3 * (capturecount + 1); // +1 for safety; * 3 for pcre_exec's tuples
- ovector = g_new (int, ovector_bufsize);
- return true;
- }
+ GRegexCompileFlags options;
+
+ if (case_sensitive)
+ options = (GRegexCompileFlags)0;
+ else
+ options = (GRegexCompileFlags)G_REGEX_CASELESS;
+
+ GError * err = 0;
+ re = g_regex_new (pattern.c_str(), options, (GRegexMatchFlags)0, &err);
+ if (err) {
+ Log::add_err_va (_("Can't use regular expression \"%s\": %s"), pattern.c_str(), err->message);
+ g_error_free (err);
+ return false;
+ }
+
+ return true;
+ }
};
int
@@ -252,15 +213,14 @@ TextMatch :: my_regexec (const StringView& text) const
}
return _pcre_state != COMPILED
- ? PCRE_ERROR_NOMATCH
- : pcre_exec (_pcre_info->re,
- _pcre_info->extra,
- text.str,
- text.len,
- 0,
- PCRE_NOTEMPTY,
- _pcre_info->ovector,
- _pcre_info->ovector_bufsize);
+ ? -1
+ : g_regex_match_full (_pcre_info->re,
+ text.str,
+ text.len,
+ 0,
+ G_REGEX_MATCH_NOTEMPTY,
+ NULL,
+ NULL);
}
/*****
diff --git a/pan/gui/Makefile.am b/pan/gui/Makefile.am
index 3de23ae..6a87d3f 100644
--- a/pan/gui/Makefile.am
+++ b/pan/gui/Makefile.am
@@ -92,4 +92,4 @@ WINRCOBJ =
endif
pan_SOURCES = gui.cc pan.cc $(WINRC)
-pan_LDADD = ./libpangui.a $(WINRCOBJ) ../data-impl/libpandata.a ../tasks/libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../uulib/libuu.a @GTKSPELL_LIBS@ @GTK_LIBS@ @GMIME_LIBS@ @GLIB_LIBS@ @PCRE_LIBS@
+pan_LDADD = ./libpangui.a $(WINRCOBJ) ../data-impl/libpandata.a ../tasks/libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../uulib/libuu.a @GTKSPELL_LIBS@ @GTK_LIBS@ @GMIME_LIBS@ @GLIB_LIBS@
diff --git a/pan/tasks/Makefile.am b/pan/tasks/Makefile.am
index 7044cc6..46a6ea1 100644
--- a/pan/tasks/Makefile.am
+++ b/pan/tasks/Makefile.am
@@ -48,7 +48,7 @@ TEST_LDADD = ./libtasks.a \
../usenet-utils/libusenetutils.a \
../general/libgeneralutils.a \
../../uulib/libuu.a \
- @GMIME_LIBS@ @GLIB_LIBS@ @PCRE_LIBS@
+ @GMIME_LIBS@ @GLIB_LIBS@
adaptable_set_test_SOURCES = adaptable-set-test.cc
nzb_test_SOURCES = nzb-test.cc
@@ -68,7 +68,7 @@ nzb_test_LDADD = $(TEST_LDADD)
# nntp-pool-test \
# queue-test
#
-#TEST_LDADD = ./libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../gmime/libgmime.a $(GLIB_LIBS) $(PCRE_LIBS_POSIX) $(PCRE_LIBS)
+#TEST_LDADD = ./libtasks.a ../data/libdata.a ../usenet-utils/libusenetutils.a ../general/libgeneralutils.a ../../gmime/libgmime.a $(GLIB_LIBS)
#bootstrap_groups_SOURCES = bootstrap-groups.cc
#bootstrap_groups_LDADD = $(TEST_LDADD)
#bootstrap_headers_SOURCES = bootstrap-headers.cc
diff --git a/pan/usenet-utils/Makefile.am b/pan/usenet-utils/Makefile.am
index 48aee94..e845479 100644
--- a/pan/usenet-utils/Makefile.am
+++ b/pan/usenet-utils/Makefile.am
@@ -32,7 +32,7 @@ noinst_PROGRAMS = \
url-find-test
TESTS = $(noinst_PROGRAMS)
-TEST_LDADD = ./libusenetutils.a ../general/libgeneralutils.a @GMIME_LIBS@ @GLIB_LIBS@ @PCRE_LIBS@
+TEST_LDADD = ./libusenetutils.a ../general/libgeneralutils.a @GMIME_LIBS@ @GLIB_LIBS@
gnksa_test_SOURCES = gnksa-test.cc
gnksa_test_LDADD = $(TEST_LDADD)
message_check_test_SOURCES = message-check-test.cc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]