[geany/geany-plugins] 18408e: Merge pull request #694 from LarsGit223/utils-ext
Frank Lanitz
git-noreply at xxxxx
Sun Mar 4 06:24:14 UTC 2018
Branch: refs/heads/master
Author: Frank Lanitz <frank at frank.uvena.de>
Committer: GitHub <noreply at github.com>
Date: Sun, 04 Mar 2018 06:24:14 UTC
Commit: 18408ec176350c15fe7648700bb05e02c7a70260
https://github.com/geany/geany-plugins/commit/18408ec176350c15fe7648700bb05e02c7a70260
Log Message:
-----------
Merge pull request #694 from LarsGit223/utils-ext
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