[gnome-commander/gcmd-1-3] Fixed problem #616891 (build error on RHEL 5.5)



commit 93e763cf23ade697088402b5bfbdede188e732c6
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Tue Jun 1 00:36:41 2010 +0200

    Fixed problem #616891 (build error on RHEL 5.5)

 src/dialogs/gnome-cmd-advrename-regex-dialog.cc |    6 ++--
 src/gnome-cmd-advrename-dialog.cc               |   25 -----------------------
 src/gnome-cmd-regex.h                           |   25 ++++++++++++++++++++++-
 3 files changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-advrename-regex-dialog.cc b/src/dialogs/gnome-cmd-advrename-regex-dialog.cc
index 72a1a78..ce67948 100644
--- a/src/dialogs/gnome-cmd-advrename-regex-dialog.cc
+++ b/src/dialogs/gnome-cmd-advrename-regex-dialog.cc
@@ -122,9 +122,9 @@ gboolean gnome_cmd_advrename_regex_dialog_new (const gchar *title, GtkWindow *pa
     gtk_container_add (GTK_CONTAINER (align), check);
 
 #if !GLIB_CHECK_VERSION (2, 14, 0)
-    box = gnome_cmd_hint_box_new (_("Some regular expressions functionality is disabled. "
-                                    "To enable it's necessary to build GNOME Commander with GLib â?¥ 2.14. "
-                                    "Please contact your package maintainer about that."));
+    GtkWidget *box = gnome_cmd_hint_box_new (_("Some regular expressions functionality is disabled. "
+                                               "To enable it's necessary to build GNOME Commander with GLib â?¥ 2.14. "
+                                               "Please contact your package maintainer about that."));
     gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);
 #endif
 
diff --git a/src/gnome-cmd-advrename-dialog.cc b/src/gnome-cmd-advrename-dialog.cc
index bda8109..711e673 100644
--- a/src/gnome-cmd-advrename-dialog.cc
+++ b/src/gnome-cmd-advrename-dialog.cc
@@ -631,10 +631,6 @@ void GnomeCmdAdvrenameDialog::update_new_filenames()
             rx.push_back(r);
     }
 
-#if !GLIB_CHECK_VERSION (2, 14, 0)
-    vector<pair<int,int> > match;
-#endif
-
     for (gboolean valid_iter=gtk_tree_model_get_iter_first (files, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (files, &i))
     {
         GnomeCmdFile *f;
@@ -653,29 +649,8 @@ void GnomeCmdAdvrenameDialog::update_new_filenames()
 
             gchar *prev_fname = fname;
 
-#if GLIB_CHECK_VERSION (2, 14, 0)
             fname = r->replace(prev_fname);
-#else
-            match.clear();
-
-            for (gchar *s=prev_fname; *s && r->match(s); s+=r->end())
-                if (r->length()>0)
-                    match.push_back(make_pair(r->start(), r->end()));
-
-            gchar *src = prev_fname;
-            gchar *dest = fname = (gchar *) g_malloc (strlen(prev_fname) + match.size()*r->to.size() + 1);    // allocate new fname big enough to hold all data
-
-            for (vector<pair<int,int> >::const_iterator i=match.begin(); i!=match.end(); ++i)
-            {
-                memcpy(dest, src, i->first);
-                dest += i->first;
-                src += i->second;
-                memcpy(dest, r->to.c_str(), r->to.size());
-                dest += r->to.size();
-            }
 
-            strcpy(dest, src);
-#endif
             g_free (prev_fname);
         }
 
diff --git a/src/gnome-cmd-regex.h b/src/gnome-cmd-regex.h
index eb53d5c..1051276 100644
--- a/src/gnome-cmd-regex.h
+++ b/src/gnome-cmd-regex.h
@@ -229,7 +229,30 @@ namespace GnomeCmd
 #if GLIB_CHECK_VERSION (2, 14, 0)
         return g_regex_replace (re, s, -1, 0, replacement.c_str(), G_REGEX_MATCH_NOTEMPTY, NULL);
 #else
-        return NULL;
+        regmatch_t pmatch;
+
+        memset(&pmatch, 0, sizeof(pmatch));
+
+        std::vector<std::pair<int,int> > match;
+
+        for (const gchar *i=s; *i && regexec(&re,i,1,&pmatch,0)==0; i+=pmatch.rm_eo)
+            if (pmatch.rm_so!=pmatch.rm_eo)
+                match.push_back(std::make_pair(pmatch.rm_so,pmatch.rm_eo));
+
+        gchar *dest = (gchar *) g_malloc (strlen(s) + match.size()*replacement.size() + 1),    // allocate new string big enough to hold all data
+              *retval = dest;
+
+        for (std::vector<std::pair<int,int> >::const_iterator i=match.begin(); i!=match.end(); ++i)
+        {
+            dest += i->first;
+            src += i->second;
+            memcpy(dest, replacement.c_str(), replacement.size());
+            dest += replacement.size();
+        }
+
+        strcpy(dest, src);
+
+        return retval;
 #endif
     }
 }



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