gnome-system-monitor r2288 - in trunk: . src



Author: bdejean
Date: Tue Jan 29 22:42:33 2008
New Revision: 2288
URL: http://svn.gnome.org/viewvc/gnome-system-monitor?rev=2288&view=rev

Log:
Use Glib::Regex whenever possible.
I can't find how to retrieve groups for now, so pcrecpp is still required.


Modified:
   trunk/configure.in
   trunk/src/defaulttable.h
   trunk/src/lsof.cpp
   trunk/src/prettytable.cpp

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Jan 29 22:42:33 2008
@@ -2,7 +2,7 @@
 
 AC_PREREQ(2.52)
 
-AC_INIT([gnome-system-monitor], [2.21.5],
+AC_INIT([gnome-system-monitor], [2.21.90],
         [http://bugzilla.gnome.org/enter_bug.cgi?product=system-monitor])
 AC_CONFIG_SRCDIR(configure.in)
 AC_CONFIG_HEADERS(config.h)
@@ -32,10 +32,11 @@
 GNOME_ICON_THEME_REQUIRED=2.15.3
 PCRECPP_REQUIRED=6.4
 GTKMM_REQUIRED=2.8
+GLIBMM_REQUIRED=2.14
 LIBXML_REQUIRED=2.0
 RSVG_REQUIRED=2.12
 
-PKG_CHECK_MODULES(PROCMAN, glib-2.0 >= $GLIB_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgtop-2.0 >= $LIBGTOP_REQUIRED libwnck-1.0 >= $LIBWNCK_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gtkmm-2.4 >= $GTKMM_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED librsvg-2.0 >= $RSVG_REQUIRED)
+PKG_CHECK_MODULES(PROCMAN, glib-2.0 >= $GLIB_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgtop-2.0 >= $LIBGTOP_REQUIRED libwnck-1.0 >= $LIBWNCK_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0 >= $GNOME_VFS_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gtkmm-2.4 >= $GTKMM_REQUIRED libxml-2.0 >= $LIBXML_REQUIRED librsvg-2.0 >= $RSVG_REQUIRED glibmm-2.4 >= $GLIBMM_REQUIRED)
 
 
 AC_ARG_ENABLE([pcrecpp], AS_HELP_STRING([--enable-pcrecpp], [Enable pcrecpp. You really want this ! (but default: disabled)]), [enable_pcrecpp=$enableval], [enable_pcrecpp=no])

Modified: trunk/src/defaulttable.h
==============================================================================
--- trunk/src/defaulttable.h	(original)
+++ trunk/src/defaulttable.h	Tue Jan 29 22:42:33 2008
@@ -2,17 +2,22 @@
 #define _PROCMAN_DEFAULTTABLE_H_
 
 #include <string>
-#include "regex.h"
+#include <glibmm.h>
 
 /* This file contains prettynames and icons for well-known applications, that by default has no .desktop entry */
 
 struct PrettyTableItem
 {
-  pcrecpp::RE* command;
+  Glib::RefPtr<Glib::Regex> command;
   std::string icon;
+
+  PrettyTableItem(const std::string& a_command, const std::string& a_icon)
+  : command(Glib::Regex::create("^(" + a_command + ")$")),
+    icon(a_icon)
+  { }
 };
 
-#define ITEM(CMD, ICON) { new pcrecpp::RE((CMD)), (ICON) }
+#define ITEM PrettyTableItem
 
 /* The current table is only a test */
 static const PrettyTableItem default_table[] = {

Modified: trunk/src/lsof.cpp
==============================================================================
--- trunk/src/lsof.cpp	(original)
+++ trunk/src/lsof.cpp	Tue Jan 29 22:42:33 2008
@@ -26,14 +26,26 @@
 namespace
 {
 
-  class LsofBase
+  class Lsof
   {
-    virtual bool matches(const string &filename) const = 0;
+    Glib::RefPtr<Glib::Regex> re;
+
+    bool matches(const string &filename) const
+    {
+      return this->re->match(filename);
+    }
 
   public:
 
-    virtual ~LsofBase()
-    { }
+    Lsof(const string &pattern, bool caseless)
+    {
+      Glib::RegexCompileFlags flags = static_cast<Glib::RegexCompileFlags>(0);
+
+      if (caseless)
+	flags |= Glib::REGEX_CASELESS;
+
+      this->re = Glib::Regex::create(pattern, flags);
+    }
 
 
     template<typename OutputIterator>
@@ -57,126 +69,6 @@
   };
 
 
-#if 0
-
-  class Lsof
-    : public LsofBase
-  {
-    string pattern;
-    bool caseless;
-
-    virtual bool matches(const string &filename) const
-    {
-      if (this->caseless) {
-	char *cp, *cf;
-	cp = g_utf8_strdown(this->pattern.c_str(), -1);
-	cf = g_utf8_strdown(filename.c_str(), -1);
-	string p(cp), f(cf);
-	g_free(cp);
-	g_free(cf);
-	return f.find(p) != string::npos;
-      }
-
-      return filename.find(this->pattern) != string::npos;
-    }
-
-  public:
-
-    Lsof(const string &pattern, bool caseless)
-      : pattern(pattern), caseless(caseless)
-    { }
-  };
-
-#elif 1
-
-  class Lsof
-    : public LsofBase
-  {
-    pcrecpp::RE re;
-
-    virtual bool matches(const string &filename) const
-    {
-      return this->re.PartialMatch(filename);
-    }
-
-  public:
-
-    Lsof(const string &pattern, bool caseless)
-      : re(pattern, pcrecpp::RE_Options().set_caseless(caseless).set_utf8(true))
-    { }
-  };
-
-#else
-  class Lsof
-    : public LsofBase
-  {
-    string pattern;
-    bool caseless;
-
-
-    static string escape(const string &s)
-    {
-      char *escaped = g_strescape(s.c_str(), "");
-      string ret(escaped);
-      g_free(escaped);
-
-      return ret;
-    }
-
-
-    virtual bool matches(const string &filename) const
-    {
-      string argv1, argv2;
-
-      argv1 = escape(this->pattern);
-      argv2 = escape(filename);
-
-      const char *argv[7];
-
-      argv[0] = "python";
-      argv[1] = "-c";
-      argv[2] = "import sys, re; "
-	"sys.exit(re.search(sys.argv[1], sys.argv[2], "
-	"(bool(sys.argv[3]) and re.I or 0)) is None)";
-      argv[3] = argv1.c_str();
-      argv[4] = argv2.c_str();
-      argv[5] = this->caseless ? "1" : "0";
-      argv[6] = NULL;
-
-      int status;
-      GError *error = NULL;
-
-      if (g_spawn_sync(NULL, // cwd
-		       const_cast<gchar**>(argv), NULL, // argv and env
-		       static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH
-					       | G_SPAWN_STDOUT_TO_DEV_NULL
-					       | G_SPAWN_STDERR_TO_DEV_NULL), // flags
-		       NULL, NULL, // child_setup and user_data
-		       NULL, NULL, // stdin, stdout
-		       &status,
-		       &error)) {
-	if (!error and WIFEXITED(status))
-	  return WEXITSTATUS(status) == 0;
-      }
-
-      if (error) {
-	procman_debug("Failed to spawn python for re : %s", error->message);
-	g_error_free(error);
-      }
-
-      return false;
-    }
-
-  public:
-
-    Lsof(const string &pattern, bool caseless)
-      : pattern(pattern), caseless(caseless)
-    { }
-  };
-
-#endif
-
-
 
   // GUI Stuff
 

Modified: trunk/src/prettytable.cpp
==============================================================================
--- trunk/src/prettytable.cpp	(original)
+++ trunk/src/prettytable.cpp	Tue Jan 29 22:42:33 2008
@@ -119,7 +119,7 @@
 bool PrettyTable::get_default_icon_name(const string &cmd, string &name)
 {
   for (size_t i = 0; i != G_N_ELEMENTS(default_table); ++i) {
-    if (default_table[i].command->FullMatch(cmd)) {
+    if (default_table[i].command->match(cmd)) {
       name = default_table[i].icon;
       return true;
     }



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