summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c58
-rw-r--r--src/core/wee-string.h4
-rw-r--r--src/plugins/guile/weechat-guile-api.c44
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp38
-rw-r--r--src/plugins/lua/weechat-lua-api.c38
-rw-r--r--src/plugins/perl/weechat-perl-api.c38
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/python/weechat-python-api.c40
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c50
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c42
-rw-r--r--src/plugins/weechat-plugin.h10
11 files changed, 362 insertions, 1 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 3f7b62fa2..28e960c18 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -48,6 +48,7 @@
#include "weechat.h"
#include "wee-string.h"
#include "wee-config.h"
+#include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-utf8.h"
#include "../gui/gui-color.h"
@@ -500,6 +501,63 @@ string_expand_home (const char *path)
}
/*
+ * Evaluate a path by replacing (in this order):
+ * 1. "%h" (at beginning of string) by WeeChat home directory.
+ * 2. "~" by user home directory (call to string_expand_home)
+ * 3. evaluated variables (see /help eval)
+ *
+ * Returns the evaluated path, NULL if error.
+ *
+ * Note: result must be freed after use.
+ */
+
+char *
+string_eval_path_home (const char *path,
+ struct t_hashtable *pointers,
+ struct t_hashtable *extra_vars,
+ struct t_hashtable *options)
+{
+ char *path1, *path2, *path3;
+ int length;
+
+ if (!path)
+ return NULL;
+
+ path1 = NULL;
+ path2 = NULL;
+ path3 = NULL;
+
+ /* replace "%h" by Weechat home */
+ if (strncmp (path, "%h", 2) == 0)
+ {
+ length = strlen (weechat_home) + strlen (path + 2) + 1;
+ path1 = malloc (length);
+ if (path1)
+ snprintf (path1, length, "%s%s", weechat_home, path + 2);
+ }
+ else
+ path1 = strdup (path);
+ if (!path1)
+ goto end;
+
+ /* replace "~" by user home */
+ path2 = string_expand_home (path1);
+ if (!path2)
+ goto end;
+
+ /* evaluate content of path */
+ path3 = eval_expression (path2, pointers, extra_vars, options);
+
+end:
+ if (path1)
+ free (path1);
+ if (path2)
+ free (path2);
+
+ return path3;
+}
+
+/*
* Removes quotes at beginning/end of string (ignores spaces if there are before
* first quote or after last quote).
*
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 683660eed..0c0b1f807 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -44,6 +44,10 @@ extern int string_match (const char *string, const char *mask,
extern char *string_replace (const char *string, const char *search,
const char *replace);
extern char *string_expand_home (const char *path);
+extern char *string_eval_path_home (const char *path,
+ struct t_hashtable *pointers,
+ struct t_hashtable *extra_vars,
+ struct t_hashtable *options);
extern char *string_remove_quotes (const char *string, const char *quotes);
extern char *string_strip (const char *string, int left, int right,
const char *chars);
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index 1c9762913..14bc1cfa4 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -480,6 +480,49 @@ weechat_guile_api_string_eval_expression (SCM expr, SCM pointers,
}
SCM
+weechat_guile_api_string_eval_path_home (SCM path, SCM pointers,
+ SCM extra_vars, SCM options)
+{
+ char *result;
+ SCM return_value;
+ struct t_hashtable *c_pointers, *c_extra_vars, *c_options;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ if (!scm_is_string (path) || !scm_list_p (pointers)
+ || !scm_list_p (extra_vars) || !scm_list_p (options))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ c_pointers = weechat_guile_alist_to_hashtable (
+ pointers,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ c_extra_vars = weechat_guile_alist_to_hashtable (
+ extra_vars,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ c_options = weechat_guile_alist_to_hashtable (
+ options,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (API_SCM_TO_STRING(path),
+ c_pointers, c_extra_vars,
+ c_options);
+
+ if (c_pointers)
+ weechat_hashtable_free (c_pointers);
+ if (c_extra_vars)
+ weechat_hashtable_free (c_extra_vars);
+ if (c_options)
+ weechat_hashtable_free (c_options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
+SCM
weechat_guile_api_mkdir_home (SCM directory, SCM mode)
{
API_INIT_FUNC(1, "mkdir_home", API_RETURN_ERROR);
@@ -4660,6 +4703,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(string_is_command_char, 1);
API_DEF_FUNC(string_input_for_buffer, 1);
API_DEF_FUNC(string_eval_expression, 4);
+ API_DEF_FUNC(string_eval_path_home, 4);
API_DEF_FUNC(mkdir_home, 2);
API_DEF_FUNC(mkdir, 2);
API_DEF_FUNC(mkdir_parents, 2);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index 11b4b6c8a..0be1fc1ea 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -421,6 +421,43 @@ API_FUNC(string_eval_expression)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_eval_path_home)
+{
+ struct t_hashtable *pointers, *extra_vars, *options;
+ char *result;
+
+ API_INIT_FUNC(1, "string_eval_path_home", "shhh", API_RETURN_EMPTY);
+
+ v8::String::Utf8Value path(args[0]);
+ pointers = weechat_js_object_to_hashtable (
+ args[1]->ToObject(),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_js_object_to_hashtable (
+ args[2]->ToObject(),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ options = weechat_js_object_to_hashtable (
+ args[3]->ToObject(),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (*path, pointers, extra_vars,
+ options);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+ if (options)
+ weechat_hashtable_free (options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(mkdir_home)
{
int mode;
@@ -4681,6 +4718,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
API_DEF_FUNC(string_eval_expression);
+ API_DEF_FUNC(string_eval_path_home);
API_DEF_FUNC(mkdir_home);
API_DEF_FUNC(mkdir);
API_DEF_FUNC(mkdir_parents);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index ce704a73d..2b3270a92 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -441,6 +441,43 @@ API_FUNC(string_eval_expression)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_eval_path_home)
+{
+ const char *path;
+ struct t_hashtable *pointers, *extra_vars, *options;
+ char *result;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ if (lua_gettop (L) < 4)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ path = lua_tostring (L, -4);
+ pointers = weechat_lua_tohashtable (L, -3,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_lua_tohashtable (L, -2,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ options = weechat_lua_tohashtable (L, -1,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (path, pointers, extra_vars,
+ options);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+ if (options)
+ weechat_hashtable_free (options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(mkdir_home)
{
const char *directory;
@@ -4957,6 +4994,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(string_is_command_char),
API_DEF_FUNC(string_input_for_buffer),
API_DEF_FUNC(string_eval_expression),
+ API_DEF_FUNC(string_eval_path_home),
API_DEF_FUNC(mkdir_home),
API_DEF_FUNC(mkdir),
API_DEF_FUNC(mkdir_parents),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index afcf09d42..dddcb9500 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -437,6 +437,43 @@ API_FUNC(string_eval_expression)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_eval_path_home)
+{
+ char *path, *result;
+ struct t_hashtable *pointers, *extra_vars, *options;
+ dXSARGS;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ if (items < 4)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ path = SvPV_nolen (ST (0));
+ pointers = weechat_perl_hash_to_hashtable (ST (1),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_perl_hash_to_hashtable (ST (2),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ options = weechat_perl_hash_to_hashtable (ST (3),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (path, pointers, extra_vars,
+ options);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+ if (options)
+ weechat_hashtable_free (options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(mkdir_home)
{
dXSARGS;
@@ -4899,6 +4936,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
API_DEF_FUNC(string_eval_expression);
+ API_DEF_FUNC(string_eval_path_home);
API_DEF_FUNC(mkdir_home);
API_DEF_FUNC(mkdir);
API_DEF_FUNC(mkdir_parents);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index bf5484b7d..cee134d90 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -614,6 +614,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->string_match = &string_match;
new_plugin->string_replace = &string_replace;
new_plugin->string_expand_home = &string_expand_home;
+ new_plugin->string_eval_path_home = &string_eval_path_home;
new_plugin->string_remove_quotes = &string_remove_quotes;
new_plugin->string_strip = &string_strip;
new_plugin->string_convert_escaped_chars = &string_convert_escaped_chars;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index 02d3658cf..77f2195df 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -419,6 +419,45 @@ API_FUNC(string_eval_expression)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_eval_path_home)
+{
+ char *path, *result;
+ struct t_hashtable *pointers, *extra_vars, *options;
+ PyObject *dict, *dict2, *dict3, *return_value;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ path = NULL;
+ pointers = NULL;
+ extra_vars = NULL;
+ options = NULL;
+ if (!PyArg_ParseTuple (args, "sOOO", &path, &dict, &dict2, &dict3))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+ pointers = weechat_python_dict_to_hashtable (dict,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_python_dict_to_hashtable (dict2,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ options = weechat_python_dict_to_hashtable (dict3,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (path, pointers, extra_vars,
+ options);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+ if (options)
+ weechat_hashtable_free (options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(mkdir_home)
{
char *directory;
@@ -4880,6 +4919,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(string_is_command_char),
API_DEF_FUNC(string_input_for_buffer),
API_DEF_FUNC(string_eval_expression),
+ API_DEF_FUNC(string_eval_path_home),
API_DEF_FUNC(mkdir_home),
API_DEF_FUNC(mkdir),
API_DEF_FUNC(mkdir_parents),
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 68eba9f5f..1cd26074f 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -508,6 +508,55 @@ weechat_ruby_api_string_eval_expression (VALUE class, VALUE expr,
}
static VALUE
+weechat_ruby_api_string_eval_path_home (VALUE class, VALUE path,
+ VALUE pointers, VALUE extra_vars,
+ VALUE options)
+{
+ char *c_path, *result;
+ struct t_hashtable *c_pointers, *c_extra_vars, *c_options;
+ VALUE return_value;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ if (NIL_P (path) || NIL_P (pointers) || NIL_P (extra_vars)
+ || NIL_P (options))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ Check_Type (path, T_STRING);
+ Check_Type (pointers, T_HASH);
+ Check_Type (extra_vars, T_HASH);
+ Check_Type (options, T_HASH);
+
+ c_path = StringValuePtr (path);
+ c_pointers = weechat_ruby_hash_to_hashtable (
+ pointers,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ c_extra_vars = weechat_ruby_hash_to_hashtable (
+ extra_vars,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ c_options = weechat_ruby_hash_to_hashtable (
+ options,
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (c_path, c_pointers, c_extra_vars,
+ c_options);
+
+ if (c_pointers)
+ weechat_hashtable_free (c_pointers);
+ if (c_extra_vars)
+ weechat_hashtable_free (c_extra_vars);
+ if (c_options)
+ weechat_hashtable_free (c_options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static VALUE
weechat_ruby_api_mkdir_home (VALUE class, VALUE directory, VALUE mode)
{
char *c_directory;
@@ -6005,6 +6054,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(string_is_command_char, 1);
API_DEF_FUNC(string_input_for_buffer, 1);
API_DEF_FUNC(string_eval_expression, 4);
+ API_DEF_FUNC(string_eval_path_home, 4);
API_DEF_FUNC(mkdir_home, 2);
API_DEF_FUNC(mkdir, 2);
API_DEF_FUNC(mkdir_parents, 2);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index 03b7ecfa5..851d423d1 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -574,6 +574,47 @@ API_FUNC(string_eval_expression)
API_RETURN_STRING_FREE(result);
}
+API_FUNC(string_eval_path_home)
+{
+ Tcl_Obj *objp;
+ char *path, *result;
+ struct t_hashtable *pointers, *extra_vars, *options;
+ int i;
+
+ API_INIT_FUNC(1, "string_eval_path_home", API_RETURN_EMPTY);
+ if (objc < 5)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ path = Tcl_GetStringFromObj (objv[1], &i);
+ pointers = weechat_tcl_dict_to_hashtable (
+ interp, objv[2],
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_tcl_dict_to_hashtable (
+ interp, objv[3],
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+ options = weechat_tcl_dict_to_hashtable (
+ interp, objv[4],
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_path_home (path, pointers, extra_vars,
+ options);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+ if (options)
+ weechat_hashtable_free (options);
+
+ API_RETURN_STRING_FREE(result);
+}
+
API_FUNC(mkdir_home)
{
Tcl_Obj *objp;
@@ -5356,6 +5397,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
API_DEF_FUNC(string_eval_expression);
+ API_DEF_FUNC(string_eval_path_home);
API_DEF_FUNC(mkdir_home);
API_DEF_FUNC(mkdir);
API_DEF_FUNC(mkdir_parents);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 4f402f044..3987e3b15 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -57,7 +57,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 "20150114-01"
+#define WEECHAT_PLUGIN_API_VERSION "20150624-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -276,6 +276,10 @@ struct t_weechat_plugin
char *(*string_replace) (const char *string, const char *search,
const char *replace);
char *(*string_expand_home) (const char *path);
+ char *(*string_eval_path_home) (const char *path,
+ struct t_hashtable *pointers,
+ struct t_hashtable *extra_vars,
+ struct t_hashtable *options);
char *(*string_remove_quotes) (const char *string, const char *quotes);
char *(*string_strip) (const char *string, int left, int right,
const char *chars);
@@ -1040,6 +1044,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->string_replace)(__string, __search, __replace)
#define weechat_string_expand_home(__path) \
(weechat_plugin->string_expand_home)(__path)
+#define weechat_string_eval_path_home(__path, __pointers, \
+ __extra_vars, __options) \
+ (weechat_plugin->string_eval_path_home)(__path, __pointers, \
+ __extra_vars, __options)
#define weechat_string_remove_quotes(__string, __quotes) \
(weechat_plugin->string_remove_quotes)(__string, __quotes)
#define weechat_string_strip(__string, __left, __right, __chars) \