mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 01:03:14 +02:00
api: add support of escaped strings in function string_eval_expression and command /eval
This commit is contained in:
+10
-6
@@ -6735,12 +6735,13 @@ command_init ()
|
||||
"\n"
|
||||
"Some variables are replaced in expression, using the format "
|
||||
"${variable}, variable can be, by order of priority :\n"
|
||||
" 1. a color (format: \"color:xxx\")\n"
|
||||
" 2. an info (format: \"info:name,arguments\", arguments are "
|
||||
" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n"
|
||||
" 2. a color (format: \"color:xxx\")\n"
|
||||
" 3. an info (format: \"info:name,arguments\", arguments are "
|
||||
"optional)\n"
|
||||
" 3. an option (format: \"file.section.option\")\n"
|
||||
" 4. a local variable in buffer\n"
|
||||
" 5. a hdata name/variable (the value is automatically converted "
|
||||
" 4. an option (format: \"file.section.option\")\n"
|
||||
" 5. a local variable in buffer\n"
|
||||
" 6. a hdata name/variable (the value is automatically converted "
|
||||
"to string), by default \"window\" and \"buffer\" point to current "
|
||||
"window/buffer.\n"
|
||||
"Format for hdata can be one of following:\n"
|
||||
@@ -6755,13 +6756,16 @@ command_init ()
|
||||
"For name of hdata and variables, please look at \"Plugin API "
|
||||
"reference\", function \"weechat_hdata_get\".\n"
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
"Examples (simple strings):\n"
|
||||
" /eval -n ${info:version} ==> 0.4.3\n"
|
||||
" /eval -n ${weechat.look.scroll_amount} ==> 3\n"
|
||||
" /eval -n ${window} ==> 0x2549aa0\n"
|
||||
" /eval -n ${window.buffer} ==> 0x2549320\n"
|
||||
" /eval -n ${window.buffer.full_name} ==> core.weechat\n"
|
||||
" /eval -n ${window.buffer.number} ==> 1\n"
|
||||
" /eval -n ${\\t} ==> <tab>\n"
|
||||
"\n"
|
||||
"Examples (conditions):\n"
|
||||
" /eval -n -c ${window.buffer.number} > 2 ==> 0\n"
|
||||
" /eval -n -c ${window.win_width} > 100 ==> 1\n"
|
||||
" /eval -n -c (8 > 12) || (5 > 2) ==> 1\n"
|
||||
|
||||
+11
-5
@@ -252,14 +252,20 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
return strdup (ptr_value);
|
||||
}
|
||||
|
||||
/* 2. look for a color */
|
||||
/* 2. convert escaped chars */
|
||||
if (strncmp (text, "esc:", 4) == 0)
|
||||
return string_convert_escaped_chars (text + 4);
|
||||
if ((text[0] == '\\') && text[1] && (text[1] != '\\'))
|
||||
return string_convert_escaped_chars (text);
|
||||
|
||||
/* 3. look for a color */
|
||||
if (strncmp (text, "color:", 6) == 0)
|
||||
{
|
||||
ptr_value = gui_color_get_custom (text + 6);
|
||||
return strdup ((ptr_value) ? ptr_value : "");
|
||||
}
|
||||
|
||||
/* 3. look for an info */
|
||||
/* 4. look for an info */
|
||||
if (strncmp (text, "info:", 5) == 0)
|
||||
{
|
||||
ptr_value = NULL;
|
||||
@@ -279,7 +285,7 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
return strdup ((ptr_value) ? ptr_value : "");
|
||||
}
|
||||
|
||||
/* 4. look for name of option: if found, return this value */
|
||||
/* 5. look for name of option: if found, return this value */
|
||||
if (strncmp (text, "sec.data.", 9) == 0)
|
||||
{
|
||||
ptr_value = hashtable_get (secure_hashtable_data, text + 9);
|
||||
@@ -312,7 +318,7 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
}
|
||||
}
|
||||
|
||||
/* 5. look for local variable in buffer */
|
||||
/* 6. look for local variable in buffer */
|
||||
ptr_buffer = hashtable_get (pointers, "buffer");
|
||||
if (ptr_buffer)
|
||||
{
|
||||
@@ -321,7 +327,7 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
return strdup (ptr_value);
|
||||
}
|
||||
|
||||
/* 6. look for hdata */
|
||||
/* 7. look for hdata */
|
||||
value = NULL;
|
||||
hdata_name = NULL;
|
||||
list_name = NULL;
|
||||
|
||||
Reference in New Issue
Block a user