api: add argument "recurse_subdirs" in function exec_on_files()

v2.8-utf8proc
Sébastien Helleu 2017-07-04 21:58:48 +02:00
parent 275389864b
commit ff448b9096
13 changed files with 53 additions and 21 deletions

View File

@ -23,6 +23,10 @@ New features::
* buflist: add option buflist.look.add_newline (issue #1027)
* fset: new plugin "fset" (fast set of WeeChat and plugins options)
Improvements::
* api: add argument "recurse_subdirs" in function exec_on_files()
Bug fixes::
* buflist: fix crash in auto-scroll of bar when the buflist item is not the first item in the bar

View File

@ -3171,7 +3171,7 @@ weechat.mkdir_parents("/tmp/my/dir", 0755)
==== exec_on_files
_Updated in 1.5._
_Updated in 1.5, 2.0._
Find files in a directory and execute a callback on each file.
@ -3180,6 +3180,7 @@ Prototype:
[source,C]
----
void weechat_exec_on_files (const char *directory,
int recurse_subdirs,
int hidden_files,
void (*callback)(void *data,
const char *filename),
@ -3189,6 +3190,7 @@ void weechat_exec_on_files (const char *directory,
Arguments:
* _directory_: directory for searching files
* _recurse_subdirs_: 1 to recurse into sub-directories (_WeeChat ≥ 2.0_)
* _hidden_files_: 1 to include hidden files, otherwise 0
* _callback_: function called for each file found, arguments:
** _void *data_: pointer
@ -3204,7 +3206,7 @@ void callback (void *data, const char *filename)
/* ... */
}
...
weechat_exec_on_files ("/tmp", 0, &callback, NULL);
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
----
[NOTE]

View File

@ -3226,7 +3226,7 @@ weechat.mkdir_parents("/tmp/my/dir", 0755)
==== exec_on_files
_Mis à jour dans la 1.5._
_Mis à jour dans la 1.5, 2.0._
Balayer les fichiers dans un répertoire et exécuter une fonction de rappel
pour chaque fichier.
@ -3236,6 +3236,7 @@ Prototype :
[source,C]
----
void weechat_exec_on_files (const char *directory,
int recurse_subdirs,
int hidden_files,
void (*callback)(void *data,
const char *filename),
@ -3245,6 +3246,7 @@ void weechat_exec_on_files (const char *directory,
Paramètres :
* _directory_ : répertoire où chercher les fichiers
* _recurse_subdirs_ : 1 pour entrer dans les sous-répertoires (_WeeChat ≥ 2.0_)
* _hidden_files_ : 1 pour inclure les fichiers cachés, sinon 0
* _callback_ : fonction appelée pour chaque fichier trouvé, paramètres :
** _void *data_ : pointeur
@ -3261,7 +3263,7 @@ void callback (void *data, const char *filename)
/* ... */
}
...
weechat_exec_on_files ("/tmp", 0, &callback, NULL);
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
----
[NOTE]

View File

@ -3286,7 +3286,7 @@ weechat.mkdir_parents("/tmp/my/dir", 0755)
==== exec_on_files
// TRANSLATION MISSING
_Updated in 1.5._
_Updated in 1.5, 2.0._
Cerca i file in una cartella ed esegue una callback su ogni file.
@ -3295,6 +3295,7 @@ Prototipo:
[source,C]
----
void weechat_exec_on_files (const char *directory,
int recurse_subdirs,
int hidden_files,
void (*callback)(void *data,
const char *filename),
@ -3304,6 +3305,8 @@ void weechat_exec_on_files (const char *directory,
Argomenti:
* _directory_: cartella in cui cercare i file
// TRANSLATION MISSING
* _recurse_subdirs_: 1 to recurse into sub-directories (_WeeChat ≥ 2.0_)
* _hidden_files_: 1 per includere i file nascosti, altrimenti 0
* _callback_: funzione chiamata per ogni file trovato, argomenti:
** _void *data_: puntatore
@ -3319,7 +3322,7 @@ void callback (void *data, const char *filename)
/* ... */
}
...
weechat_exec_on_files ("/tmp", 0, &callback, NULL);
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
----
[NOTE]

View File

@ -3176,7 +3176,8 @@ weechat.mkdir_parents("/tmp/my/dir", 0755)
==== exec_on_files
_WeeChat バージョン 1.5 で更新。_
// TRANSLATION MISSING
_Updated in 1.5, 2.0._
ディレクトリ中のファイルを探し、各ファイルに対してコールバックを実行。
@ -3185,6 +3186,7 @@ _WeeChat バージョン 1.5 で更新。_
[source,C]
----
void weechat_exec_on_files (const char *directory,
int recurse_subdirs,
int hidden_files,
void (*callback)(void *data,
const char *filename),
@ -3194,6 +3196,8 @@ void weechat_exec_on_files (const char *directory,
引数:
* _directory_: ファイルを検索するディレクトリ
// TRANSLATION MISSING
* _recurse_subdirs_: 1 to recurse into sub-directories (_WeeChat ≥ 2.0_)
* _hidden_files_: 検索対象に隠しファイルを含める場合は 1、含めない場合は 0
* _callback_: 各ファイルに対して呼び出すコールバック関数、引数:
** _void *data_: ポインタ
@ -3209,7 +3213,7 @@ void callback (void *data, const char *filename)
/* ... */
}
...
weechat_exec_on_files ("/tmp", 0, &callback, NULL);
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
----
[NOTE]

View File

@ -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);

View File

@ -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 */

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)