SF.net SVN: geany:[5755] trunk

colombanw at users.sourceforge.net colombanw at xxxxx
Sun May 1 14:38:58 UTC 2011


Revision: 5755
          http://geany.svn.sourceforge.net/geany/?rev=5755&view=rev
Author:   colombanw
Date:     2011-05-01 14:38:57 +0000 (Sun, 01 May 2011)

Log Message:
-----------
Fix pattern filtering when not searching in subdirectories

grep's --include option doesn't filter files passed explicitly to grep,
so when we build the file list to search in, take the filters into
account.
Also drop the --include options in this case since they aren't useful.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-04-30 21:50:50 UTC (rev 5754)
+++ trunk/ChangeLog	2011-05-01 14:38:57 UTC (rev 5755)
@@ -1,3 +1,9 @@
+2011-05-01  Colomban Wendling  <colomban(at)geany(dot)org>
+
+ * src/search.c:
+   Fix pattern filtering when not searching in subdirectories.
+
+
 2011-04-30  Colomban Wendling  <colomban(at)geany(dot)org>
 
  * src/project.c:

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2011-04-30 21:50:50 UTC (rev 5754)
+++ trunk/src/search.c	2011-05-01 14:38:57 UTC (rev 5755)
@@ -1642,14 +1642,27 @@
 }
 
 
+static gboolean pattern_list_match(GSList *patterns, const gchar *str)
+{
+	GSList *item;
+
+	foreach_slist(item, patterns)
+	{
+		if (g_pattern_match_string(item->data, str))
+			return TRUE;
+	}
+	return FALSE;
+}
+
+
 /* Creates an argument vector of strings, copying argv_prefix[] values for
  * the first arguments, then followed by filenames found in dir.
  * Returns NULL if no files were found, otherwise returned vector should be fully freed. */
 static gchar **search_get_argv(const gchar **argv_prefix, const gchar *dir)
 {
-	guint prefix_len, list_len, i;
+	guint prefix_len, list_len, i, j;
 	gchar **argv;
-	GSList *list, *item;
+	GSList *list, *item, *patterns = NULL;
 	GError *error = NULL;
 
 	g_return_val_if_fail(dir != NULL, NULL);
@@ -1667,13 +1680,40 @@
 
 	argv = g_new(gchar*, prefix_len + list_len + 1);
 
-	for (i = 0; i < prefix_len; i++)
-		argv[i] = g_strdup(argv_prefix[i]);
+	for (i = 0, j = 0; i < prefix_len; i++)
+	{
+		if (g_str_has_prefix(argv_prefix[i], "--include="))
+		{
+			const gchar *pat = &(argv_prefix[i][10]); /* the pattern part of the argument */
 
-	foreach_slist(item, list)
-		argv[i++] = item->data;
+			patterns = g_slist_prepend(patterns, g_pattern_spec_new(pat));
+		}
+		else
+			argv[j++] = g_strdup(argv_prefix[i]);
+	}
 
-	argv[i] = NULL;
+	if (patterns)
+	{
+		GSList *pat;
+
+		foreach_slist(item, list)
+		{
+			if (pattern_list_match(patterns, item->data))
+				argv[j++] = item->data;
+			else
+				g_free(item->data);
+		}
+		foreach_slist(pat, patterns)
+			g_pattern_spec_free(pat->data);
+		g_slist_free(patterns);
+	}
+	else
+	{
+		foreach_slist(item, list)
+			argv[j++] = item->data;
+	}
+
+	argv[j] = NULL;
 	g_slist_free(list);
 	return argv;
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list