diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-02-28 21:11:34 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-02-28 21:11:34 +0000 |
commit | e4cc18210575125c7aea1ce62496772f73768158 (patch) | |
tree | e9f1d1bbdd1b94a020151d8aa8f8b3a84e8e32e0 /src | |
parent | 8c662f69f97d1adfd83c8fd7b6427bdfa386ca98 (diff) | |
download | weechat-e4cc18210575125c7aea1ce62496772f73768158.zip |
Script plugins now load scripts in WeeChat system share directory
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua.c | 24 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl.c | 24 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 24 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 24 | ||||
-rw-r--r-- | src/plugins/scripts/weechat-script.c | 56 | ||||
-rw-r--r-- | src/plugins/scripts/weechat-script.h | 2 |
6 files changed, 70 insertions, 84 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 798433c12..e2efb8d6b 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -1593,8 +1593,8 @@ weechat_lua_cmd (t_weechat_plugin *plugin, char *server, char *command, char *arguments, char *handler_args, void *handler_pointer) { - int argc, path_length, handler_found; - char **argv, *path_script, *dir_home; + int argc, handler_found; + char **argv, *path_script; t_plugin_script *ptr_script; t_plugin_handler *ptr_handler; @@ -1705,25 +1705,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin, if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0) { /* load Lua script */ - if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\"))) - path_script = NULL; - else - { - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { - path_length = strlen (dir_home) + strlen (argv[1]) + 16; - path_script = (char *) malloc (path_length * sizeof (char)); - if (path_script) - snprintf (path_script, path_length, "%s/lua/%s", - dir_home, argv[1]); - else - path_script = NULL; - free (dir_home); - } - else - path_script = NULL; - } + path_script = weechat_script_search_full_name (plugin, "lua", argv[1]); weechat_lua_load (plugin, (path_script) ? path_script : argv[1]); if (path_script) free (path_script); diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index f8c581480..c1605e22a 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -1401,8 +1401,8 @@ weechat_perl_cmd (t_weechat_plugin *plugin, char *server, char *command, char *arguments, char *handler_args, void *handler_pointer) { - int argc, path_length, handler_found; - char **argv, *path_script, *dir_home; + int argc, handler_found; + char **argv, *path_script; t_plugin_script *ptr_script; t_plugin_handler *ptr_handler; @@ -1513,25 +1513,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin, if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0) { /* load Perl script */ - if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\"))) - path_script = NULL; - else - { - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { - path_length = strlen (dir_home) + strlen (argv[1]) + 16; - path_script = (char *) malloc (path_length * sizeof (char)); - if (path_script) - snprintf (path_script, path_length, "%s/perl/%s", - dir_home, argv[1]); - else - path_script = NULL; - free (dir_home); - } - else - path_script = NULL; - } + path_script = weechat_script_search_full_name (plugin, "perl", argv[1]); weechat_perl_load (plugin, (path_script) ? path_script : argv[1]); if (path_script) free (path_script); diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index b7afb327a..cca2db855 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -1365,8 +1365,8 @@ weechat_python_cmd (t_weechat_plugin *plugin, char *server, char *command, char *arguments, char *handler_args, void *handler_pointer) { - int argc, path_length, handler_found; - char **argv, *path_script, *dir_home; + int argc, handler_found; + char **argv, *path_script; t_plugin_script *ptr_script; t_plugin_handler *ptr_handler; @@ -1477,25 +1477,7 @@ weechat_python_cmd (t_weechat_plugin *plugin, if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0) { /* load Python script */ - if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\"))) - path_script = NULL; - else - { - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { - path_length = strlen (dir_home) + strlen (argv[1]) + 16; - path_script = (char *) malloc (path_length * sizeof (char)); - if (path_script) - snprintf (path_script, path_length, "%s/python/%s", - dir_home, argv[1]); - else - path_script = NULL; - free (dir_home); - } - else - path_script = NULL; - } + path_script = weechat_script_search_full_name (plugin, "python", argv[1]); weechat_python_load (plugin, (path_script) ? path_script : argv[1]); if (path_script) free (path_script); diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 13e4d1d3b..13f1e927f 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -1544,8 +1544,8 @@ weechat_ruby_cmd (t_weechat_plugin *plugin, char *server, char *command, char *arguments, char *handler_args, void *handler_pointer) { - int argc, path_length, handler_found; - char **argv, *path_script, *dir_home; + int argc, handler_found; + char **argv, *path_script; t_plugin_script *ptr_script; t_plugin_handler *ptr_handler; @@ -1656,25 +1656,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin, if (plugin->ascii_strcasecmp (plugin, argv[0], "load") == 0) { /* load Ruby script */ - if ((strstr (argv[1], "/")) || (strstr (argv[1], "\\"))) - path_script = NULL; - else - { - dir_home = plugin->get_info (plugin, "weechat_dir", NULL); - if (dir_home) - { - path_length = strlen (dir_home) + strlen (argv[1]) + 16; - path_script = (char *) malloc (path_length * sizeof (char)); - if (path_script) - snprintf (path_script, path_length, "%s/ruby/%s", - dir_home, argv[1]); - else - path_script = NULL; - free (dir_home); - } - else - path_script = NULL; - } + path_script = weechat_script_search_full_name (plugin, "ruby", argv[1]); weechat_ruby_load (plugin, (path_script) ? path_script : argv[1]); if (path_script) free (path_script); diff --git a/src/plugins/scripts/weechat-script.c b/src/plugins/scripts/weechat-script.c index 636d121e3..c5ee3cca3 100644 --- a/src/plugins/scripts/weechat-script.c +++ b/src/plugins/scripts/weechat-script.c @@ -85,6 +85,62 @@ weechat_script_search (t_weechat_plugin *plugin, } /* + * weechat_script_search_full_name: search the full path name of a script + */ + +char * +weechat_script_search_full_name (t_weechat_plugin *plugin, + char *language, char *filename) +{ + char *final_name, *dir_home, *dir_system; + int length; + struct stat st; + + if ((strstr(filename, "/")) || (strstr(filename, "\\"))) + return strdup(filename); + + /* try WeeChat user's dir */ + dir_home = plugin->get_info (plugin, "weechat_dir", NULL); + if (dir_home) + { + length = strlen (dir_home) + strlen (language) + strlen (filename) + 16; + final_name = (char *) malloc (length); + if (final_name) + { + snprintf (final_name, length, "%s/%s/%s", dir_home, language, filename); + if ((stat (final_name, &st) == 0) && (st.st_size > 0)) + { + free (dir_home); + return final_name; + } + free (final_name); + } + free (dir_home); + } + + /* try WeeChat system dir */ + dir_system = plugin->get_info (plugin, "weechat_sharedir", NULL); + if (dir_system) + { + length = strlen (dir_system) + strlen (dir_system) + strlen (filename) + 16; + final_name = (char *) malloc (length); + if (final_name) + { + snprintf (final_name,length, "%s/%s/%s", dir_system, language, filename); + if ((stat (final_name, &st) == 0) && (st.st_size > 0)) + { + free (dir_system); + return final_name; + } + free (final_name); + } + free (dir_system); + } + + return NULL; +} + +/* * weechat_script_add: add a script to list of scripts */ diff --git a/src/plugins/scripts/weechat-script.h b/src/plugins/scripts/weechat-script.h index d60c03c97..007bc8713 100644 --- a/src/plugins/scripts/weechat-script.h +++ b/src/plugins/scripts/weechat-script.h @@ -43,6 +43,8 @@ extern void weechat_script_auto_load (t_weechat_plugin *, char *, int (*)(t_weechat_plugin *, char *)); extern t_plugin_script *weechat_script_search (t_weechat_plugin *, t_plugin_script **, char *); +extern char *weechat_script_search_full_name (t_weechat_plugin *, + char *, char *); extern t_plugin_script *weechat_script_add (t_weechat_plugin *, t_plugin_script **, char *, char *, char *, char *, char *); |