summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-07-04 21:58:48 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-07-04 22:01:14 +0200
commitff448b909687fb9214ecd6afa39f7b996b2ae2f4 (patch)
tree1c82cb70a418b0f5e5c623c7fd2ff05d5d4e7b8f /src
parent275389864be6b83f1b0fd2d51e5899b759e0b966 (diff)
downloadweechat-ff448b909687fb9214ecd6afa39f7b996b2ae2f4.zip
api: add argument "recurse_subdirs" in function exec_on_files()
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-completion.c3
-rw-r--r--src/core/wee-upgrade.c2
-rw-r--r--src/core/wee-util.c15
-rw-r--r--src/core/wee-util.h3
-rw-r--r--src/plugins/plugin-script.c2
-rw-r--r--src/plugins/plugin.c3
-rw-r--r--src/plugins/script/script-completion.c4
-rw-r--r--src/plugins/weechat-plugin.h11
8 files changed, 30 insertions, 13 deletions
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index ec710e1b6..6c30084e7 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -897,6 +897,7 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
(plugin_path2) ?
plugin_path2 : ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path)),
+ 1,
0,
&completion_list_add_plugins_installed_exec_cb,
completion);
@@ -912,7 +913,7 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
if (dir_name)
{
snprintf (dir_name, length, "%s/plugins", WEECHAT_LIBDIR);
- util_exec_on_files (dir_name, 0,
+ util_exec_on_files (dir_name, 1, 0,
&completion_list_add_plugins_installed_exec_cb,
completion);
free (dir_name);
diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c
index 6bf2f0577..3dbf05272 100644
--- a/src/core/wee-upgrade.c
+++ b/src/core/wee-upgrade.c
@@ -907,7 +907,7 @@ upgrade_weechat_end ()
/* remove .upgrade files */
util_exec_on_files (weechat_home,
- 0,
+ 0, 0,
&upgrade_weechat_remove_file_cb, NULL);
/* display message for end of /upgrade with duration */
diff --git a/src/core/wee-util.c b/src/core/wee-util.c
index 22eb0e43e..2b85e82d8 100644
--- a/src/core/wee-util.c
+++ b/src/core/wee-util.c
@@ -485,7 +485,8 @@ util_mkdir_parents (const char *directory, int mode)
*/
void
-util_exec_on_files (const char *directory, int hidden_files,
+util_exec_on_files (const char *directory, int recurse_subdirs,
+ int hidden_files,
void (*callback)(void *data, const char *filename),
void *callback_data)
{
@@ -507,7 +508,17 @@ util_exec_on_files (const char *directory, int hidden_files,
snprintf (complete_filename, sizeof (complete_filename),
"%s/%s", directory, entry->d_name);
lstat (complete_filename, &statbuf);
- if (!S_ISDIR(statbuf.st_mode))
+ if (S_ISDIR(statbuf.st_mode))
+ {
+ if (recurse_subdirs
+ && (strcmp (entry->d_name, ".") != 0)
+ && (strcmp (entry->d_name, "..") != 0))
+ {
+ util_exec_on_files (complete_filename, 1, hidden_files,
+ callback, callback_data);
+ }
+ }
+ else
{
(*callback) (callback_data, complete_filename);
}
diff --git a/src/core/wee-util.h b/src/core/wee-util.h
index fe17e0117..77cef07f1 100644
--- a/src/core/wee-util.h
+++ b/src/core/wee-util.h
@@ -46,7 +46,8 @@ extern void util_catch_signal (int signum, void (*handler)(int));
extern int util_mkdir_home (const char *directory, int mode);
extern int util_mkdir (const char *directory, int mode);
extern int util_mkdir_parents (const char *directory, int mode);
-extern void util_exec_on_files (const char *directory, int hidden_files,
+extern void util_exec_on_files (const char *directory, int recurse_subdirs,
+ int hidden_files,
void (*callback)(void *data,
const char *filename),
void *callback_data);
diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c
index 09202ccc7..50e10534d 100644
--- a/src/plugins/plugin-script.c
+++ b/src/plugins/plugin-script.c
@@ -419,7 +419,7 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
snprintf (dir_name, dir_length,
"%s/%s/autoload", dir_home, weechat_plugin->name);
- weechat_exec_on_files (dir_name, 0, callback, NULL);
+ weechat_exec_on_files (dir_name, 0, 0, callback, NULL);
free (dir_name);
}
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 6d9d6583a..20d02859b 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -1025,6 +1025,7 @@ plugin_auto_load (int argc, char **argv)
util_exec_on_files ((plugin_path2) ?
plugin_path2 : ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path)),
+ 1,
0,
&plugin_auto_load_file, &plugin_args);
if (plugin_path)
@@ -1039,7 +1040,7 @@ plugin_auto_load (int argc, char **argv)
if (dir_name)
{
snprintf (dir_name, length, "%s/plugins", WEECHAT_LIBDIR);
- util_exec_on_files (dir_name, 0,
+ util_exec_on_files (dir_name, 1, 0,
&plugin_auto_load_file, &plugin_args);
free (dir_name);
}
diff --git a/src/plugins/script/script-completion.c b/src/plugins/script/script-completion.c
index e889bb6a5..8d3279286 100644
--- a/src/plugins/script/script-completion.c
+++ b/src/plugins/script/script-completion.c
@@ -214,14 +214,14 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
/* look for files in "~/.weechat/<language>/" */
snprintf (directory, length,
"%s/%s", weechat_home, script_language[i]);
- weechat_exec_on_files (directory, 0,
+ weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
/* look for files in "~/.weechat/<language>/autoload/" */
snprintf (directory, length,
"%s/%s/autoload", weechat_home, script_language[i]);
- weechat_exec_on_files (directory, 0,
+ weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
}
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 8dfcff406..05285959b 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
-#define WEECHAT_PLUGIN_API_VERSION "20170530-02"
+#define WEECHAT_PLUGIN_API_VERSION "20170704-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -362,7 +362,8 @@ struct t_weechat_plugin
int (*mkdir_home) (const char *directory, int mode);
int (*mkdir) (const char *directory, int mode);
int (*mkdir_parents) (const char *directory, int mode);
- void (*exec_on_files) (const char *directory, int hidden_files,
+ void (*exec_on_files) (const char *directory, int recurse_subdirs,
+ int hidden_files,
void (*callback)(void *data, const char *filename),
void *callback_data);
char *(*file_get_content) (const char *filename);
@@ -1279,9 +1280,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->mkdir)(__directory, __mode)
#define weechat_mkdir_parents(__directory, __mode) \
(weechat_plugin->mkdir_parents)(__directory, __mode)
-#define weechat_exec_on_files(__directory, __hidden_files, __callback, \
+#define weechat_exec_on_files(__directory, __recurse_subdirs, \
+ __hidden_files, __callback, \
__callback_data) \
- (weechat_plugin->exec_on_files)(__directory, __hidden_files, \
+ (weechat_plugin->exec_on_files)(__directory, __recurse_subdirs, \
+ __hidden_files, \
__callback, __callback_data)
#define weechat_file_get_content(__filename) \
(weechat_plugin->file_get_content)(__filename)