[gparted] Implement fallback if Glib::Regex class is missing (#695279)



commit 456932846bfbfbd77bbf49165b9eb6c2b84e0da6
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Mar 3 22:58:05 2013 +0000

    Implement fallback if Glib::Regex class is missing (#695279)
    
    GParted fails to compile on RHEL/CentOS 5.9 because it doesn't provide
    the Glib::Regex class.  Glib::Regex class requires glibmm >= 2.14,
    however RHEL/CentOS 5.9 only provides glibmm 2.12.
    
    Add an autoconf check for the Glib::Regex class and fallback code using
    the POSIX regex function.  Fall back code is the same as that used prior
    to commit:
        b6f1c56fb1e6119131a475ff6362f8cd59b1b33b
        Enhance regexp_label method to handle unicode characters
    
    Bug #695279 - GParted doesn't compile on RHEL / CentOS 5.9

 configure.in |   11 +++++++++++
 src/Utils.cc |   19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index 4098d39..f8962ad 100644
--- a/configure.in
+++ b/configure.in
@@ -252,6 +252,17 @@ AC_SUBST([GTKMM_LIBS])
 AC_SUBST([GTKMM_CFLAGS])
 
 
+dnl Check for glibmm >= 2.14 to determine availability of Glib::Regex class
+AC_MSG_CHECKING([for Glib::Regex class])
+PKG_CHECK_EXISTS(
+       [glibmm-2.4 >= 2.14.0],
+       [AC_DEFINE([HAVE_GLIB_REGEX], 1, [Define to 1 if glibmm provides Glib::Regex class.])
+        AC_MSG_RESULT([yes])
+       ],
+       [AC_MSG_RESULT([no])]
+)
+
+
 dnl GTKMM 2.16 needed for gtk_show_uri()
 PKG_CHECK_EXISTS([gtkmm-2.4 >= 2.16.0],
   [AC_DEFINE([HAVE_GTK_SHOW_URI], 1, [Define to 1 if you have gtk_show_uri])],
diff --git a/src/Utils.cc b/src/Utils.cc
index 4bf4de4..545df82 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -23,7 +23,11 @@
 #include <sstream>
 #include <fstream>
 #include <iomanip>
+#ifdef HAVE_GLIB_REGEX
 #include <glibmm/regex.h>
+#else
+#include <regex.h>
+#endif
 #include <locale.h>
 #include <uuid/uuid.h>
 #include <cerrno>
@@ -506,6 +510,7 @@ Glib::ustring Utils::regexp_label( const Glib::ustring & text
 {
        //Extract text from a regular sub-expression or pattern.
        //  E.g., "text we don't want (text we want)"
+#ifdef HAVE_GLIB_REGEX
        std::vector<Glib::ustring> results;
        Glib::RefPtr<Glib::Regex> myregexp =
                Glib::Regex::create( pattern
@@ -518,6 +523,20 @@ Glib::ustring Utils::regexp_label( const Glib::ustring & text
                return results[ 1 ] ;
        else
                return "" ;
+#else /* ! HAVE_GLIB_REGEX */
+       Glib::ustring label = "" ;
+       regex_t preg ;
+       int nmatch = 2 ;
+       regmatch_t pmatch[ 2 ] ;
+       int rc = regcomp( &preg, pattern .c_str(), REG_EXTENDED | REG_ICASE | REG_NEWLINE ) ;
+       if ( rc == 0 )
+       {
+               if ( regexec( &preg, text .c_str(), nmatch, pmatch, 0 ) == 0 )
+                       label = text .substr( pmatch[ 1 ] .rm_so, pmatch[ 1 ] .rm_eo - pmatch[ 1 ] .rm_so ) ;
+               regfree( &preg ) ;
+       }
+       return label ;
+#endif
 }
 
 Glib::ustring Utils::trim( const Glib::ustring & src, const Glib::ustring & c /* = " \t\r\n" */ )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]