1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

script: display error when installing/removing/loading script if plugin for language is not loaded

This commit is contained in:
Sebastien Helleu
2012-09-04 12:57:26 +02:00
parent 3849cb49bc
commit 7756be5fea
23 changed files with 577 additions and 268 deletions
+153 -94
View File
@@ -61,7 +61,7 @@ script_action_list ()
scripts_loaded = 0;
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
snprintf (hdata_name, sizeof (hdata_name),
"%s_script", script_language[i]);
@@ -114,7 +114,7 @@ script_action_list_input (int send_to_buffer)
buf[0] = '\0';
length = 0;
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
snprintf (hdata_name, sizeof (hdata_name),
"%s_script", script_language[i]);
@@ -178,6 +178,15 @@ script_action_load (const char *name, int quiet)
return;
}
/* check that plugin for this language is loaded */
if (!script_plugin_loaded[language])
{
weechat_printf (NULL,
_("%s: plugin \"%s\" is not loaded"),
SCRIPT_PLUGIN_NAME, script_language[language]);
return;
}
/* execute command (for example: "/perl load iset.pl") */
snprintf (str_command, sizeof (str_command),
"/%s load %s%s",
@@ -260,7 +269,7 @@ script_action_unload (const char *name, int quiet)
else
{
/* unload script by using name (example: "iset") */
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
snprintf (hdata_name, sizeof (hdata_name),
"%s_script", script_language[i]);
@@ -366,7 +375,7 @@ script_action_reload (const char *name, int quiet)
else
{
/* reload script by using name (example: "iset") */
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
snprintf (hdata_name, sizeof (hdata_name),
"%s_script", script_language[i]);
@@ -426,7 +435,7 @@ script_action_install_process_cb (void *data, const char *command,
{
char *pos, *filename, *filename2, str_signal[256];
int quiet, length;
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
quiet = (data) ? 1 : 0;
@@ -485,20 +494,19 @@ script_action_install_process_cb (void *data, const char *command,
}
/*
* script_action_install: install script(s) marked for install
* script_action_get_next_script_to_install: get next script to install
* according to "install_order" in
* script
*/
void
script_action_install (int quiet)
struct t_script_repo *
script_action_get_next_script_to_install ()
{
struct t_repo_script *ptr_script, *ptr_script_to_install;
char *filename, *url;
int length;
struct t_hashtable *options;
struct t_script_repo *ptr_script, *ptr_script_to_install;
ptr_script_to_install = NULL;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->install_order > 0)
@@ -509,43 +517,79 @@ script_action_install (int quiet)
}
}
if (ptr_script_to_install)
{
filename = script_config_get_script_download_filename (ptr_script_to_install,
NULL);
if (filename)
{
options = weechat_hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (options)
{
length = 4 + strlen (ptr_script_to_install->url) + 1;
url = malloc (length);
if (url)
{
if (!weechat_config_boolean (script_config_look_quiet_actions))
{
weechat_printf (NULL,
_("%s: downloading script \"%s\"..."),
SCRIPT_PLUGIN_NAME,
ptr_script_to_install->name_with_extension);
}
return ptr_script_to_install;
}
snprintf (url, length, "url:%s",
ptr_script_to_install->url);
weechat_hashtable_set (options, "file_out", filename);
weechat_hook_process_hashtable (url, options, 30000,
&script_action_install_process_cb,
(quiet) ? (void *)1 : (void *)0);
free (url);
/*
* script_action_install: install script(s) marked for install
*/
void
script_action_install (int quiet)
{
struct t_script_repo *ptr_script_to_install;
char *filename, *url;
int length;
struct t_hashtable *options;
while (1)
{
ptr_script_to_install = script_action_get_next_script_to_install ();
/* no more script to install? just exit function */
if (!ptr_script_to_install)
return;
/*
* script to install and plugin is loaded: exit loop and go on with
* install
*/
if (script_plugin_loaded[ptr_script_to_install->language])
break;
/* plugin not loaded for language of script: display error */
weechat_printf (NULL,
_("%s: script \"%s\" can not be installed because "
"plugin \"%s\" is not loaded"),
SCRIPT_PLUGIN_NAME,
ptr_script_to_install->name_with_extension,
script_language[ptr_script_to_install->language]);
}
filename = script_config_get_script_download_filename (ptr_script_to_install,
NULL);
if (filename)
{
options = weechat_hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (options)
{
length = 4 + strlen (ptr_script_to_install->url) + 1;
url = malloc (length);
if (url)
{
if (!weechat_config_boolean (script_config_look_quiet_actions))
{
weechat_printf (NULL,
_("%s: downloading script \"%s\"..."),
SCRIPT_PLUGIN_NAME,
ptr_script_to_install->name_with_extension);
}
weechat_hashtable_free (options);
snprintf (url, length, "url:%s",
ptr_script_to_install->url);
weechat_hashtable_set (options, "file_out", filename);
weechat_hook_process_hashtable (url, options, 30000,
&script_action_install_process_cb,
(quiet) ? (void *)1 : (void *)0);
free (url);
}
free (filename);
weechat_hashtable_free (options);
}
free (filename);
}
}
@@ -556,52 +600,12 @@ script_action_install (int quiet)
void
script_action_remove (const char *name, int quiet)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
char str_signal[256], *filename;
int length;
ptr_script = script_repo_search_by_name_ext (name);
if (ptr_script)
{
if (!(ptr_script->status & SCRIPT_STATUS_INSTALLED))
{
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is not installed"),
SCRIPT_PLUGIN_NAME, name);
}
}
else if (ptr_script->status & SCRIPT_STATUS_HELD)
{
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is held"),
SCRIPT_PLUGIN_NAME, name);
}
}
else
{
length = 3 + strlen (ptr_script->name_with_extension) + 1;
filename = malloc (length);
if (filename)
{
snprintf (filename, length,
"%s%s",
(quiet && weechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "",
ptr_script->name_with_extension);
snprintf (str_signal, sizeof (str_signal),
"%s_script_remove",
script_language[ptr_script->language]);
weechat_hook_signal_send (str_signal,
WEECHAT_HOOK_SIGNAL_STRING,
filename);
free (filename);
}
}
}
else
if (!ptr_script)
{
if (!quiet)
{
@@ -609,6 +613,61 @@ script_action_remove (const char *name, int quiet)
_("%s: script \"%s\" not found"),
SCRIPT_PLUGIN_NAME, name);
}
return;
}
/* check that script is installed */
if (!(ptr_script->status & SCRIPT_STATUS_INSTALLED))
{
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is not installed"),
SCRIPT_PLUGIN_NAME, name);
}
return;
}
/* check that script is not held */
if (ptr_script->status & SCRIPT_STATUS_HELD)
{
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is held"),
SCRIPT_PLUGIN_NAME, name);
}
return;
}
/* check that plugin for this language is loaded */
if (!script_plugin_loaded[ptr_script->language])
{
weechat_printf (NULL,
_("%s: script \"%s\" can not be removed "
"because plugin \"%s\" is not loaded"),
SCRIPT_PLUGIN_NAME,
ptr_script->name_with_extension,
script_language[ptr_script->language]);
return;
}
/* ask plugin to remove script */
length = 3 + strlen (ptr_script->name_with_extension) + 1;
filename = malloc (length);
if (filename)
{
snprintf (filename, length,
"%s%s",
(quiet && weechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "",
ptr_script->name_with_extension);
snprintf (str_signal, sizeof (str_signal),
"%s_script_remove",
script_language[ptr_script->language]);
weechat_hook_signal_send (str_signal,
WEECHAT_HOOK_SIGNAL_STRING,
filename);
free (filename);
}
}
@@ -620,7 +679,7 @@ script_action_remove (const char *name, int quiet)
int
script_action_hold (const char *name, int quiet)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
ptr_script = script_repo_search_by_name_ext (name);
if (ptr_script)
@@ -768,7 +827,7 @@ script_action_show_source_process_cb (void *data, const char *command,
char *pos, *filename, *filename_loaded, line[4096], *ptr_line;
char *diff_command;
const char *ptr_diff_command;
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
FILE *file;
int length, diff_made;
@@ -898,7 +957,7 @@ script_action_show_source_process_cb (void *data, const char *command,
void
script_action_show (const char *name, int quiet)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
char *filename, *url;
int length;
struct t_hashtable *options;
@@ -1016,7 +1075,7 @@ script_action_run ()
{
char **actions, **argv, **argv_eol, *ptr_action;
int num_actions, argc, i, j, quiet, script_found;
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
if (!script_actions)
return 0;
@@ -1204,7 +1263,7 @@ script_action_run ()
else if (weechat_strcasecmp (argv[0], "upgrade") == 0)
{
script_found = 0;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
/*
@@ -1287,7 +1346,7 @@ script_action_schedule (const char *action, int need_repository, int quiet)
{
if (script_repo_file_is_uptodate ())
{
if (!repo_scripts)
if (!scripts_repo)
script_repo_file_read (quiet);
script_action_run ();
}
+7 -7
View File
@@ -35,7 +35,7 @@
struct t_gui_buffer *script_buffer = NULL;
int script_buffer_selected_line = 0;
struct t_repo_script *script_buffer_detail_script = NULL;
struct t_script_repo *script_buffer_detail_script = NULL;
int script_buffer_detail_script_last_line = 0;
int script_buffer_detail_script_line_diff = -1;
@@ -45,7 +45,7 @@ int script_buffer_detail_script_line_diff = -1;
*/
void
script_buffer_display_line_script (int line, struct t_repo_script *script)
script_buffer_display_line_script (int line, struct t_script_repo *script)
{
char str_line[16384], str_item[1024], str_color_name[256], str_color[32];
char str_format[256], str_date[64], str_key[2], utf_char[16], *tags;
@@ -359,7 +359,7 @@ script_buffer_detail_label (const char *text, int max_length)
*/
void
script_buffer_display_detail_script (struct t_repo_script *script)
script_buffer_display_detail_script (struct t_script_repo *script)
{
struct tm *tm;
char str_time[1024];
@@ -487,7 +487,7 @@ script_buffer_display_detail_script (struct t_repo_script *script)
void
script_buffer_refresh (int clear)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
int line;
char str_title[1024];
@@ -530,7 +530,7 @@ script_buffer_refresh (int clear)
{
/* list of scripts */
line = 0;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->displayed)
@@ -568,7 +568,7 @@ script_buffer_set_current_line (int line)
*/
void
script_buffer_show_detail_script (struct t_repo_script *script)
script_buffer_show_detail_script (struct t_script_repo *script)
{
if (!script_buffer)
return;
@@ -743,7 +743,7 @@ script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
/* refresh buffer */
if (strcmp (input_data, "$") == 0)
{
script_get_loaded_scripts ();
script_get_loaded_plugins_and_scripts ();
script_repo_remove_all ();
script_repo_file_read (1);
script_buffer_refresh (1);
+3 -3
View File
@@ -22,17 +22,17 @@
#define SCRIPT_BUFFER_NAME "scripts"
struct t_repo_script;
struct t_script_repo;
extern struct t_gui_buffer *script_buffer;
extern int script_buffer_selected_line;
extern struct t_repo_script *script_buffer_detail_script;
extern struct t_script_repo *script_buffer_detail_script;
extern int script_buffer_detail_script_last_line;
extern int script_buffer_detail_script_line_diff;
extern void script_buffer_refresh (int clear);
extern void script_buffer_set_current_line (int line);
extern void script_buffer_show_detail_script (struct t_repo_script *script);
extern void script_buffer_show_detail_script (struct t_script_repo *script);
extern void script_buffer_get_window_info (struct t_gui_window *window,
int *start_line_y, int *chat_height);
extern void script_buffer_check_line_outside_window ();
+2 -2
View File
@@ -42,7 +42,7 @@ void
script_command_action (struct t_gui_buffer *buffer, const char *action,
const char *arguments, int need_repository)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
char str_action[4096];
long value;
char *error;
@@ -155,7 +155,7 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
if (weechat_strcasecmp (argv[1], "search") == 0)
{
if (repo_scripts)
if (scripts_repo)
script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL);
else
script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL);
+7 -7
View File
@@ -41,14 +41,14 @@ script_completion_scripts_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
weechat_hook_completion_list_add (completion,
@@ -69,14 +69,14 @@ script_completion_scripts_installed_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->status & SCRIPT_STATUS_INSTALLED)
@@ -150,7 +150,7 @@ script_completion_scripts_files_cb (void *data, const char *completion_item,
directory = malloc (length);
if (directory)
{
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
pointers[0] = completion;
pointers[1] = script_extension[i];
@@ -183,7 +183,7 @@ script_completion_tags_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
char **list_tags;
int num_tags, i;
@@ -192,7 +192,7 @@ script_completion_tags_cb (void *data, const char *completion_item,
(void) completion_item;
(void) buffer;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->tags)
+2 -2
View File
@@ -204,7 +204,7 @@ script_config_get_xml_filename ()
*/
char *
script_config_get_script_download_filename (struct t_repo_script *script,
script_config_get_script_download_filename (struct t_script_repo *script,
const char *suffix)
{
char *path, *filename;
@@ -254,7 +254,7 @@ script_config_reload_scripts_cb (void *data, struct t_config_option *option)
(void) data;
(void) option;
if (repo_scripts)
if (scripts_repo)
{
script_repo_remove_all ();
script_repo_file_read (1);
+2 -2
View File
@@ -22,7 +22,7 @@
#define SCRIPT_CONFIG_NAME "script"
struct t_repo_script;
struct t_script_repo;
extern struct t_config_option *script_config_look_columns;
extern struct t_config_option *script_config_look_diff_color;
@@ -68,7 +68,7 @@ extern struct t_config_option *script_config_scripts_url;
extern const char *script_config_get_diff_command ();
extern char *script_config_get_dir ();
extern char *script_config_get_xml_filename ();
extern char *script_config_get_script_download_filename (struct t_repo_script *script,
extern char *script_config_get_script_download_filename (struct t_script_repo *script,
const char *suffix);
extern void script_config_hold (const char *name_with_extension);
extern void script_config_unhold (const char *name_with_extension);
+2 -2
View File
@@ -39,7 +39,7 @@ script_info_get_infolist_cb (void *data, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_infolist *ptr_infolist;
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
/* make C compiler happy */
(void) data;
@@ -68,7 +68,7 @@ script_info_get_infolist_cb (void *data, const char *infolist_name,
else
{
/* build list with all scripts matching arguments */
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (!arguments || !arguments[0]
+85 -85
View File
@@ -42,8 +42,8 @@
#include "script-config.h"
struct t_repo_script *repo_scripts = NULL;
struct t_repo_script *last_repo_script = NULL;
struct t_script_repo *scripts_repo = NULL;
struct t_script_repo *last_script_repo = NULL;
int script_repo_count = 0;
int script_repo_count_displayed = 0;
struct t_hashtable *script_repo_max_length_field = NULL;
@@ -57,14 +57,14 @@ char *script_repo_filter = NULL;
*/
int
script_repo_script_valid (struct t_repo_script *script)
script_repo_script_valid (struct t_script_repo *script)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
if (!script)
return 0;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script == script)
@@ -80,17 +80,17 @@ script_repo_script_valid (struct t_repo_script *script)
* (first script displayed is 0)
*/
struct t_repo_script *
struct t_script_repo *
script_repo_search_displayed_by_number (int number)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
int i;
if (number < 0)
return NULL;
i = 0;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->displayed)
@@ -110,12 +110,12 @@ script_repo_search_displayed_by_number (int number)
* (example: "iset")
*/
struct t_repo_script *
struct t_script_repo *
script_repo_search_by_name (const char *name)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (strcmp (ptr_script->name, name) == 0)
@@ -131,12 +131,12 @@ script_repo_search_by_name (const char *name)
* (example: "iset.pl")
*/
struct t_repo_script *
struct t_script_repo *
script_repo_search_by_name_ext (const char *name_with_extension)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (strcmp (ptr_script->name_with_extension, name_with_extension) == 0)
@@ -155,7 +155,7 @@ script_repo_search_by_name_ext (const char *name_with_extension)
*/
char *
script_repo_get_filename_loaded (struct t_repo_script *script)
script_repo_get_filename_loaded (struct t_script_repo *script)
{
const char *weechat_home;
char *filename, resolved_path[PATH_MAX];
@@ -209,7 +209,7 @@ script_repo_get_filename_loaded (struct t_repo_script *script)
*/
const char *
script_repo_get_status_for_display (struct t_repo_script *script,
script_repo_get_status_for_display (struct t_script_repo *script,
const char *list,
int collapse)
{
@@ -267,7 +267,7 @@ script_repo_get_status_for_display (struct t_repo_script *script,
*/
const char *
script_repo_get_status_desc_for_display (struct t_repo_script *script,
script_repo_get_status_desc_for_display (struct t_script_repo *script,
const char *list)
{
static char str_status[256];
@@ -346,10 +346,10 @@ script_repo_get_status_desc_for_display (struct t_repo_script *script,
* script_repo_alloc: allocate a script structure
*/
struct t_repo_script *
struct t_script_repo *
script_repo_alloc ()
{
struct t_repo_script *new_script;
struct t_script_repo *new_script;
new_script = malloc (sizeof (*new_script));
if (new_script)
@@ -388,8 +388,8 @@ script_repo_alloc ()
*/
int
script_repo_compare_scripts (struct t_repo_script *script1,
struct t_repo_script *script2)
script_repo_compare_scripts (struct t_script_repo *script1,
struct t_script_repo *script2)
{
const char *ptr_sort;
int cmp, reverse;
@@ -484,12 +484,12 @@ script_repo_compare_scripts (struct t_repo_script *script1,
* script_repo_find_pos: find position for script in list
*/
struct t_repo_script *
script_repo_find_pos (struct t_repo_script *script)
struct t_script_repo *
script_repo_find_pos (struct t_script_repo *script)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (script_repo_compare_scripts (ptr_script, script) > 0)
@@ -520,9 +520,9 @@ script_repo_set_max_length_field (const char *field, int length)
*/
void
script_repo_add (struct t_repo_script *script)
script_repo_add (struct t_script_repo *script)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
ptr_script = script_repo_find_pos (script);
if (ptr_script)
@@ -533,19 +533,19 @@ script_repo_add (struct t_repo_script *script)
if (ptr_script->prev_script)
(ptr_script->prev_script)->next_script = script;
else
repo_scripts = script;
scripts_repo = script;
ptr_script->prev_script = script;
}
else
{
/* add script to the end */
script->prev_script = last_repo_script;
script->prev_script = last_script_repo;
script->next_script = NULL;
if (repo_scripts)
last_repo_script->next_script = script;
if (scripts_repo)
last_script_repo->next_script = script;
else
repo_scripts = script;
last_repo_script = script;
scripts_repo = script;
last_script_repo = script;
}
/* set max length for fields */
@@ -587,7 +587,7 @@ script_repo_add (struct t_repo_script *script)
*/
void
script_repo_free (struct t_repo_script *script)
script_repo_free (struct t_script_repo *script)
{
if (script->name)
free (script->name);
@@ -626,20 +626,20 @@ script_repo_free (struct t_repo_script *script)
*/
void
script_repo_remove (struct t_repo_script *script)
script_repo_remove (struct t_script_repo *script)
{
struct t_repo_script *new_repo_scripts;
struct t_script_repo *new_scripts_repo;
/* remove script from list */
if (last_repo_script == script)
last_repo_script = script->prev_script;
if (last_script_repo == script)
last_script_repo = script->prev_script;
if (script->prev_script)
{
(script->prev_script)->next_script = script->next_script;
new_repo_scripts = repo_scripts;
new_scripts_repo = scripts_repo;
}
else
new_repo_scripts = script->next_script;
new_scripts_repo = script->next_script;
if (script->next_script)
(script->next_script)->prev_script = script->prev_script;
@@ -648,7 +648,7 @@ script_repo_remove (struct t_repo_script *script)
script_repo_count_displayed--;
script_repo_free (script);
repo_scripts = new_repo_scripts;
scripts_repo = new_scripts_repo;
script_repo_count--;
@@ -666,9 +666,9 @@ script_repo_remove (struct t_repo_script *script)
void
script_repo_remove_all ()
{
while (repo_scripts)
while (scripts_repo)
{
script_repo_remove (repo_scripts);
script_repo_remove (scripts_repo);
}
if (script_repo_max_length_field)
{
@@ -682,7 +682,7 @@ script_repo_remove_all ()
*/
int
script_repo_script_is_held (struct t_repo_script *script)
script_repo_script_is_held (struct t_script_repo *script)
{
const char *hold;
char *pos;
@@ -764,13 +764,13 @@ script_repo_md5sum_file (const char *filename)
*/
void
script_repo_update_status (struct t_repo_script *script)
script_repo_update_status (struct t_script_repo *script)
{
const char *weechat_home, *version;
char *filename, *md5sum;
struct stat st;
int length;
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
script->status = 0;
md5sum = NULL;
@@ -837,7 +837,7 @@ script_repo_update_status (struct t_repo_script *script)
{
length = 0;
weechat_hashtable_set (script_repo_max_length_field, "V", &length);
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
if (ptr_script->version_loaded)
@@ -856,9 +856,9 @@ script_repo_update_status (struct t_repo_script *script)
void
script_repo_update_status_all ()
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
script_repo_update_status (ptr_script);
@@ -883,7 +883,7 @@ script_repo_set_filter (const char *filter)
*/
int
script_repo_match_filter (struct t_repo_script *script)
script_repo_match_filter (struct t_script_repo *script)
{
char **words, **tags;
int num_words, num_tags, has_tag, match, i, j;
@@ -957,13 +957,13 @@ script_repo_match_filter (struct t_repo_script *script)
void
script_repo_filter_scripts (const char *search)
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
script_repo_set_filter (search);
script_repo_count_displayed = 0;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
ptr_script->displayed = (script_repo_match_filter (ptr_script));
@@ -1066,12 +1066,12 @@ script_repo_file_read (int quiet)
char *locale, *locale_language;
const char *version, *ptr_locale, *ptr_desc;
gzFile file;
struct t_repo_script *script;
struct t_script_repo *script;
int version_number, version_ok, script_ok, length;
struct tm tm_script;
struct t_hashtable *descriptions;
script_get_loaded_scripts ();
script_get_loaded_plugins_and_scripts ();
script_repo_remove_all ();
@@ -1327,7 +1327,7 @@ script_repo_file_read (int quiet)
gzclose (file);
if (repo_scripts && !quiet)
if (scripts_repo && !quiet)
{
weechat_printf (NULL,
_("%s: %d scripts for WeeChat %s"),
@@ -1335,7 +1335,7 @@ script_repo_file_read (int quiet)
weechat_info_get ("version", NULL));
}
if (!repo_scripts)
if (!scripts_repo)
{
weechat_printf (NULL,
_("%s%s: list of scripts is empty (repository file "
@@ -1383,7 +1383,7 @@ script_repo_file_update_process_cb (void *data, const char *command,
return WEECHAT_RC_OK;
}
if (script_repo_file_read (quiet) && repo_scripts)
if (script_repo_file_read (quiet) && scripts_repo)
{
if (!script_action_run ())
script_buffer_refresh (1);
@@ -1460,31 +1460,31 @@ script_repo_hdata_script_cb (void *data, const char *hdata_name)
0, NULL, NULL);
if (hdata)
{
WEECHAT_HDATA_VAR(struct t_repo_script, name, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, name_with_extension, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, language, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, author, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, mail, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, version, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, license, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, description, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, tags, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, requirements, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, min_weechat, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, max_weechat, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, md5sum, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, url, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, popularity, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, date_added, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, date_updated, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, status, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, version_loaded, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, displayed, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, install_order, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_repo_script, prev_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_repo_script, next_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(repo_scripts);
WEECHAT_HDATA_LIST(last_repo_script);
WEECHAT_HDATA_VAR(struct t_script_repo, name, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, name_with_extension, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, language, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, author, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, mail, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, version, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, license, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, description, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, tags, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, requirements, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, min_weechat, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, max_weechat, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, md5sum, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, url, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, popularity, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, date_added, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, date_updated, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, status, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, version_loaded, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, displayed, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, install_order, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, prev_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_script_repo, next_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(scripts_repo);
WEECHAT_HDATA_LIST(last_script_repo);
}
return hdata;
}
@@ -1496,7 +1496,7 @@ script_repo_hdata_script_cb (void *data, const char *hdata_name)
int
script_repo_add_to_infolist (struct t_infolist *infolist,
struct t_repo_script *script)
struct t_script_repo *script)
{
struct t_infolist_item *ptr_item;
@@ -1560,9 +1560,9 @@ script_repo_add_to_infolist (struct t_infolist *infolist,
void
script_repo_print_log ()
{
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
for (ptr_script = repo_scripts; ptr_script;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
weechat_log_printf ("");
+14 -14
View File
@@ -27,7 +27,7 @@
#define SCRIPT_STATUS_RUNNING 8
#define SCRIPT_STATUS_NEW_VERSION 16
struct t_repo_script
struct t_script_repo
{
char *name; /* script name */
char *name_with_extension; /* script name with extension */
@@ -50,28 +50,28 @@ struct t_repo_script
char *version_loaded; /* version of script loaded */
int displayed; /* script displayed? */
int install_order; /* order for install script (if >0)*/
struct t_repo_script *prev_script; /* link to previous script */
struct t_repo_script *next_script; /* link to next script */
struct t_script_repo *prev_script; /* link to previous script */
struct t_script_repo *next_script; /* link to next script */
};
extern struct t_repo_script *repo_scripts;
extern struct t_repo_script *last_repo_script;
extern struct t_script_repo *scripts_repo;
extern struct t_script_repo *last_script_repo;
extern int script_repo_count, script_repo_count_displayed;
struct t_hashtable *script_repo_max_length_field;
extern char *script_repo_filter;
extern int script_repo_script_valid (struct t_repo_script *script);
extern struct t_repo_script *script_repo_search_displayed_by_number (int number);
extern struct t_repo_script *script_repo_search_by_name (const char *name);
extern struct t_repo_script *script_repo_search_by_name_ext (const char *name_with_extension);
extern char *script_repo_get_filename_loaded (struct t_repo_script *script);
extern const char *script_repo_get_status_for_display (struct t_repo_script *script,
extern int script_repo_script_valid (struct t_script_repo *script);
extern struct t_script_repo *script_repo_search_displayed_by_number (int number);
extern struct t_script_repo *script_repo_search_by_name (const char *name);
extern struct t_script_repo *script_repo_search_by_name_ext (const char *name_with_extension);
extern char *script_repo_get_filename_loaded (struct t_script_repo *script);
extern const char *script_repo_get_status_for_display (struct t_script_repo *script,
const char *list,
int collapse);
extern const char *script_repo_get_status_desc_for_display (struct t_repo_script *script,
extern const char *script_repo_get_status_desc_for_display (struct t_script_repo *script,
const char *list);
extern void script_repo_remove_all ();
extern void script_repo_update_status (struct t_repo_script *script);
extern void script_repo_update_status (struct t_script_repo *script);
extern void script_repo_update_status_all ();
extern void script_repo_set_filter (const char *filter);
extern void script_repo_filter_scripts (const char *search);
@@ -82,7 +82,7 @@ extern void script_repo_file_update (int quiet);
extern struct t_hdata *script_repo_hdata_script_cb (void *data,
const char *hdata_name);
extern int script_repo_add_to_infolist (struct t_infolist *infolist,
struct t_repo_script *script);
struct t_script_repo *script);
extern void script_repo_print_log ();
#endif /* __WEECHAT_SCRIPT_REPO_H */
+75 -14
View File
@@ -45,9 +45,12 @@ WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
struct t_weechat_plugin *weechat_script_plugin = NULL;
char *script_language[] = { "guile", "lua", "perl", "python", "ruby", "tcl", NULL };
char *script_extension[] = { "scm", "lua", "pl", "py", "rb", "tcl", NULL };
char *script_language[SCRIPT_NUM_LANGUAGES] =
{ "guile", "lua", "perl", "python", "ruby", "tcl" };
char *script_extension[SCRIPT_NUM_LANGUAGES] =
{ "scm", "lua", "pl", "py", "rb", "tcl" };
int script_plugin_loaded[SCRIPT_NUM_LANGUAGES];
struct t_hashtable *script_loaded = NULL;
struct t_hook *script_timer_refresh = NULL;
@@ -62,7 +65,7 @@ script_language_search (const char *language)
{
int i;
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
if (strcmp (script_language[i], language) == 0)
return i;
@@ -83,7 +86,7 @@ script_language_search_by_extension (const char *extension)
{
int i;
for (i = 0; script_extension[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
if (strcmp (script_extension[i], extension) == 0)
return i;
@@ -94,18 +97,37 @@ script_language_search_by_extension (const char *extension)
}
/*
* script_get_loaded_scripts: get loaded scripts (in hashtable)
* script_get_loaded_plugins_and_scripts: get loaded plugins (in array of
* integers) and scripts (in hashtable)
*/
void
script_get_loaded_scripts ()
script_get_loaded_plugins_and_scripts ()
{
int i;
int i, language;
char hdata_name[128], *filename, *ptr_base_name;
const char *ptr_filename;
struct t_hdata *hdata;
void *ptr_script;
void *ptr_plugin, *ptr_script;
/* get loaded plugins */
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
script_plugin_loaded[i] = 0;
}
hdata = weechat_hdata_get ("plugin");
ptr_plugin = weechat_hdata_get_list (hdata, "weechat_plugins");
while (ptr_plugin)
{
language = script_language_search (weechat_hdata_string (hdata,
ptr_plugin,
"name"));
if (language >= 0)
script_plugin_loaded[language] = 1;
ptr_plugin = weechat_hdata_move (hdata, ptr_plugin, 1);
}
/* get loaded scripts */
if (!script_loaded)
{
script_loaded = weechat_hashtable_new (16,
@@ -117,7 +139,7 @@ script_get_loaded_scripts ()
else
weechat_hashtable_remove_all (script_loaded);
for (i = 0; script_language[i]; i++)
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
snprintf (hdata_name, sizeof (hdata_name),
"%s_script", script_language[i]);
@@ -184,7 +206,7 @@ script_timer_refresh_cb (void *data, int remaining_calls)
/* make C compiler happy */
(void) data;
script_get_loaded_scripts ();
script_get_loaded_plugins_and_scripts ();
script_repo_update_status_all ();
script_buffer_refresh (0);
@@ -194,6 +216,35 @@ script_timer_refresh_cb (void *data, int remaining_calls)
return WEECHAT_RC_OK;
}
/*
* script_signal_plugin_cb: callback for signals "plugin_loaded" and
* "plugin_unloaded"
*/
int
script_signal_plugin_cb (void *data, const char *signal, const char *type_data,
void *signal_data)
{
/* make C compiler happy */
(void) data;
(void) type_data;
if (weechat_script_plugin->debug >= 2)
{
weechat_printf (NULL, "%s: signal: %s, data: %s",
SCRIPT_PLUGIN_NAME,
signal, (char *)signal_data);
}
if (!script_timer_refresh)
{
script_timer_refresh = weechat_hook_timer (50, 0, 1,
&script_timer_refresh_cb, NULL);
}
return WEECHAT_RC_OK;
}
/*
* script_signal_script_cb: callback for signals "xxx_script_yyy"
* (example: "python_script_loaded")
@@ -205,12 +256,14 @@ script_signal_script_cb (void *data, const char *signal, const char *type_data,
{
/* make C compiler happy */
(void) data;
(void) signal;
(void) type_data;
(void) signal_data;
if (weechat_script_plugin->debug >= 2)
weechat_printf (NULL, "signal: %s, data: %s", signal, (char *)signal_data);
{
weechat_printf (NULL, "%s: signal: %s, data: %s",
SCRIPT_PLUGIN_NAME,
signal, (char *)signal_data);
}
if (!script_timer_refresh)
{
@@ -234,7 +287,7 @@ script_focus_chat_cb (void *data, struct t_hashtable *info)
struct t_gui_buffer *ptr_buffer;
long x;
char *error, str_date[64];
struct t_repo_script *ptr_script;
struct t_script_repo *ptr_script;
struct tm *tm;
/* make C compiler happy */
@@ -305,12 +358,19 @@ script_focus_chat_cb (void *data, struct t_hashtable *info)
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
int i;
/* make C compiler happy */
(void) argc;
(void) argv;
weechat_plugin = plugin;
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
script_plugin_loaded[i] = 0;
}
script_buffer_set_callbacks ();
if (!script_config_init ())
@@ -327,6 +387,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("debug_dump", &script_debug_dump_cb, NULL);
weechat_hook_signal ("window_scrolled", &script_buffer_window_scrolled_cb, NULL);
weechat_hook_signal ("plugin_*", &script_signal_plugin_cb, NULL);
weechat_hook_signal ("*_script_*", &script_signal_script_cb, NULL);
weechat_hook_focus ("chat", &script_focus_chat_cb, NULL);
+6 -3
View File
@@ -23,15 +23,18 @@
#define weechat_plugin weechat_script_plugin
#define SCRIPT_PLUGIN_NAME "script"
#define SCRIPT_NUM_LANGUAGES 6
extern struct t_weechat_plugin *weechat_script_plugin;
extern char *script_language[];
extern char *script_extension[];
extern char *script_language[SCRIPT_NUM_LANGUAGES];
extern char *script_extension[SCRIPT_NUM_LANGUAGES];
extern int script_plugin_loaded[SCRIPT_NUM_LANGUAGES];
extern struct t_hashtable *script_loaded;
extern int script_language_search (const char *language);
extern int script_language_search_by_extension (const char *extension);
extern void script_actions_add (const char *action);
extern void script_get_loaded_scripts ();
extern void script_get_loaded_plugins_and_scripts ();
#endif /* __WEECHAT_SCRIPT_H */