Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: GitHub noreply@github.com Date: Sun, 15 Oct 2017 11:42:33 UTC Commit: 23f18242fd554731de3938dc7be1a10a2af99b83 https://github.com/geany/geany-plugins/commit/23f18242fd554731de3938dc7be1a1...
Log Message: ----------- Merge pull request #628 from LarsGit223/wb-usecommonlib
workbench: use commonlib.
Modified Paths: -------------- workbench/src/Makefile.am workbench/src/utils.c workbench/src/wb_project.c
Modified: workbench/src/Makefile.am 7 lines changed, 4 insertions(+), 3 deletions(-) =================================================================== @@ -24,8 +24,9 @@ workbench_la_SOURCES = \
workbench_la_CPPFLAGS = $(AM_CPPFLAGS) \ -DG_LOG_DOMAIN="Workbench" -workbench_la_CFLAGS = $(AM_CFLAGS) -workbench_la_LIBADD = $(COMMONLIBS) - +workbench_la_CFLAGS = $(AM_CFLAGS) \ + -I$(top_srcdir)/utils/src +workbench_la_LIBADD = $(COMMONLIBS) \ + $(top_builddir)/utils/src/libgeanypluginutils.la include $(top_srcdir)/build/cppcheck.mk
Modified: workbench/src/utils.c 48 lines changed, 0 insertions(+), 48 deletions(-) =================================================================== @@ -61,54 +61,6 @@ gchar *get_relative_path(const gchar *utf8_parent, const gchar *utf8_descendant) }
-/** Check if a string matches a pattern. - * - * The function checks if @a str matches pattern @a patterns. - * - * @param patterns Pattern list. - * @param str String to check - * @return TRUE if str matches the pattern, FALSE otherwise - * - **/ -gboolean patterns_match(GSList *patterns, const gchar *str) -{ - GSList *elem = NULL; - foreach_slist (elem, patterns) - { - GPatternSpec *pattern = elem->data; - if (g_pattern_match_string(pattern, str)) - return TRUE; - } - return FALSE; -} - - -/** Get precompiled patterns. - * - * The function builds the precompiled patterns for @a patterns and returns them - * as a list. - * - * @param patterns NULL terminated string array of patterns. - * @return Pointer to GSList of patterns or NULL if patterns == NULL - * - **/ -GSList *get_precompiled_patterns(gchar **patterns) -{ - guint i; - GSList *pattern_list = NULL; - - if (!patterns) - return NULL; - - for (i = 0; patterns[i] != NULL; i++) - { - GPatternSpec *pattern_spec = g_pattern_spec_new(patterns[i]); - pattern_list = g_slist_prepend(pattern_list, pattern_spec); - } - return pattern_list; -} - - /** Combine an absolute and a relative path. * * The function combines the absolute path @a base with the relative path
Modified: workbench/src/wb_project.c 113 lines changed, 6 insertions(+), 107 deletions(-) =================================================================== @@ -26,6 +26,7 @@ #endif
#include <geanyplugin.h> +#include <../../utils/src/filelist.h> #include "wb_globals.h" #include "wb_project.h" #include "utils.h" @@ -222,86 +223,6 @@ static void wb_project_clear_idle_queue(GSList **queue) }
-/* Get the list of files for root */ -static GSList *wb_project_dir_get_file_list(WB_PROJECT_DIR *root, const gchar *utf8_path, GSList *patterns, - GSList *ignored_dirs_patterns, GSList *ignored_file_patterns, GHashTable *visited_paths) -{ - GSList *list = NULL; - GDir *dir; - const gchar *child_name; - GSList *child = NULL; - GSList *children = NULL; - gchar *locale_path = utils_get_locale_from_utf8(utf8_path); - gchar *real_path = utils_get_real_path(locale_path); - - dir = g_dir_open(locale_path, 0, NULL); - if (!dir || !real_path || g_hash_table_lookup(visited_paths, real_path)) - { - if (dir != NULL) - { - g_dir_close(dir); - } - g_free(locale_path); - g_free(real_path); - return NULL; - } - - g_hash_table_insert(visited_paths, real_path, GINT_TO_POINTER(1)); - - while ((child_name = g_dir_read_name(dir)) != NULL) - { - children = g_slist_prepend(children, g_strdup(child_name)); - } - - g_dir_close(dir); - - foreach_slist(child, children) - { - const gchar *locale_name; - gchar *locale_filename, *utf8_filename, *utf8_name; - - locale_name = child->data; - - utf8_name = utils_get_utf8_from_locale(locale_name); - locale_filename = g_build_filename(locale_path, locale_name, NULL); - utf8_filename = utils_get_utf8_from_locale(locale_filename); - - if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR)) - { - GSList *lst; - - if (!patterns_match(ignored_dirs_patterns, utf8_name)) - { - lst = wb_project_dir_get_file_list(root, utf8_filename, patterns, ignored_dirs_patterns, - ignored_file_patterns, visited_paths); - if (lst) - { - root->folder_count++; - list = g_slist_concat(list, lst); - } - } - } - else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) - { - if (patterns_match(patterns, utf8_name) && !patterns_match(ignored_file_patterns, utf8_name)) - { - root->file_count++; - list = g_slist_prepend(list, g_strdup(utf8_filename)); - } - } - - g_free(utf8_filename); - g_free(locale_filename); - g_free(utf8_name); - } - - g_slist_free_full(children, g_free); - g_free(locale_path); - - return list; -} - - /* Create a new project dir with base path "utf8_base_dir" */ static WB_PROJECT_DIR *wb_project_dir_new(const gchar *utf8_base_dir) { @@ -556,38 +477,25 @@ static guint wb_project_get_file_count(WB_PROJECT *prj) /* Rescan/update the file list of a project dir. */ static guint wb_project_dir_rescan_int(WB_PROJECT *prj, WB_PROJECT_DIR *root) { - GSList *pattern_list = NULL; - GSList *ignored_dirs_list = NULL; - GSList *ignored_file_list = NULL; - GHashTable *visited_paths; GSList *lst; GSList *elem = NULL; guint filenum = 0; gchar *searchdir; + gchar **file_patterns = NULL;
wb_project_dir_remove_from_tm_workspace(root); g_hash_table_remove_all(root->file_table);
- if (!root->file_patterns || !root->file_patterns[0]) - { - const gchar *all_pattern[] = { "*", NULL }; - pattern_list = get_precompiled_patterns((gchar **)all_pattern); - } - else + if (root->file_patterns && root->file_patterns[0]) { - pattern_list = get_precompiled_patterns(root->file_patterns); + file_patterns = root->file_patterns; }
- ignored_dirs_list = get_precompiled_patterns(root->ignored_dirs_patterns); - ignored_file_list = get_precompiled_patterns(root->ignored_file_patterns); - - visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); searchdir = get_combined_path(prj->filename, root->base_dir); root->file_count = 0; root->folder_count = 0; - lst = wb_project_dir_get_file_list - (root, searchdir, pattern_list, ignored_dirs_list, ignored_file_list, visited_paths); - g_hash_table_destroy(visited_paths); + lst = filelist_scan_directory(&(root->file_count), &(root->folder_count), + searchdir, file_patterns, root->ignored_dirs_patterns, root->ignored_file_patterns); g_free(searchdir);
foreach_slist(elem, lst) @@ -604,15 +512,6 @@ static guint wb_project_dir_rescan_int(WB_PROJECT *prj, WB_PROJECT_DIR *root) g_slist_foreach(lst, (GFunc) g_free, NULL); g_slist_free(lst);
- g_slist_foreach(pattern_list, (GFunc) g_pattern_spec_free, NULL); - g_slist_free(pattern_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 filenum; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).