[geany/geany-plugins] bc7b2e: utils: added new function "gp_filelist_filepath_matches_patterns()".

LarsDW223 git-noreply at xxxxx
Sat Feb 17 17:28:01 UTC 2018


Branch:      refs/heads/master
Author:      LarsDW223 <lars_paulsen at web.de>
Committer:   LarsDW223 <lars_paulsen at web.de>
Date:        Sat, 17 Feb 2018 17:28:01 UTC
Commit:      bc7b2e0970f894955f94810fd93edcd1064d38f1
             https://github.com/geany/geany-plugins/commit/bc7b2e0970f894955f94810fd93edcd1064d38f1

Log Message:
-----------
utils: added new function "gp_filelist_filepath_matches_patterns()".


Modified Paths:
--------------
    utils/src/filelist.c
    utils/src/filelist.h

Modified: utils/src/filelist.c
70 lines changed, 70 insertions(+), 0 deletions(-)
===================================================================
@@ -290,3 +290,73 @@ GSList *gp_filelist_scan_directory_full(guint *files, guint *folders, const gcha
 
 	return params.filelist;
 }
+
+
+/** Check if a filepath matches the given patterns.
+ *
+ * If the filepath belongs to a regular file, then TRUE will be returned if
+ * the filepath matches the patterns in file_patterns but does not match the
+ * patterns in ignored_file_patterns.
+ * 
+ * If the filepath belongs to a directory, then TRUE will be returned if it
+ * does not match the patterns in ignored_dirs_patterns.
+ *
+ * @param filepath  The file or dorectory path to check
+ * @param file_patterns
+ *                  File patterns for matching files (e.g. "*.c") or NULL
+ *                  for all files.
+ * @param ignored_dirs_patterns
+ *                  Patterns for ignored directories
+ * @param ignored_file_patterns
+ *                  Patterns for ignored files
+ * @return gboolean
+ *
+ **/
+gboolean gp_filelist_filepath_matches_patterns(const gchar *filepath, gchar **file_patterns,
+		gchar **ignored_dirs_patterns, gchar **ignored_file_patterns)
+{
+	gboolean match = FALSE;
+	GSList *file_patterns_list;
+	GSList *ignored_dirs_list;
+	GSList *ignored_file_list;
+
+	if (!file_patterns || !file_patterns[0])
+	{
+		const gchar *all_pattern[] = { "*", NULL };
+		file_patterns_list = filelist_get_precompiled_patterns((gchar **)all_pattern);
+	}
+	else
+	{
+		file_patterns_list = filelist_get_precompiled_patterns(file_patterns);
+	}
+
+	ignored_dirs_list = filelist_get_precompiled_patterns(ignored_dirs_patterns);
+	ignored_file_list = filelist_get_precompiled_patterns(ignored_file_patterns);
+
+	if (g_file_test(filepath, G_FILE_TEST_IS_DIR))
+	{
+		if (!filelist_patterns_match(ignored_dirs_list, filepath))
+		{
+			match = TRUE;
+		}
+	}
+	else if (g_file_test(filepath, G_FILE_TEST_IS_REGULAR))
+	{
+		if (filelist_patterns_match(file_patterns_list, filepath) &&
+			!filelist_patterns_match(ignored_file_list, filepath))
+		{
+			match = TRUE;
+		}
+	}
+
+	g_slist_foreach(file_patterns_list, (GFunc) g_pattern_spec_free, NULL);
+	g_slist_free(file_patterns_list);
+
+	g_slist_foreach(ignored_dirs_list, (GFunc) g_pattern_spec_free, NULL);
+	g_slist_free(ignored_dirs_list);
+
+	g_slist_foreach(ignored_file_list, (GFunc) g_pattern_spec_free, NULL);
+	g_slist_free(ignored_file_list);
+
+	return match;
+}


Modified: utils/src/filelist.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -32,6 +32,8 @@ GSList *gp_filelist_scan_directory(guint *files, guint *folders, const gchar *se
 		gchar **ignored_dirs_patterns, gchar **ignored_file_patterns);
 GSList *gp_filelist_scan_directory_full(guint *files, guint *folders, const gchar *searchdir, gchar **file_patterns,
 		gchar **ignored_dirs_patterns, gchar **ignored_file_patterns, guint flags);
+gboolean gp_filelist_filepath_matches_patterns(const gchar *filepath, gchar **file_patterns,
+		gchar **ignored_dirs_patterns, gchar **ignored_file_patterns);
 
 G_END_DECLS
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list