core: split expression before evaluating it in command "/eval -s"

This commit is contained in:
Sébastien Helleu 2015-01-30 09:58:36 +01:00
parent 8492280120
commit 9871f26f04
20 changed files with 84 additions and 56 deletions

View File

@ -19,8 +19,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
=== New features
* core: add option "-s" in command /eval to split commands (no more split by
default) (closes #324)
* core: add option "-s" in command /eval to split expression before evaluating
it (no more split by default) (closes #324)
* core: add priority in plugins to initialize them in order
* irc: add support of "account-notify" capability (closes #11, closes #246)
* irc: remove server "freenode" from default config file (closes #309)

View File

@ -236,7 +236,7 @@ infolists: zeigt Information über die Infolists an
[-n] -c <expression1> <operator> <expression2>
-n: display result without sending it to buffer (debug mode)
-s: split expression (many commands can be separated by semicolons)
-s: split expression before evaluating it (many commands can be separated by semicolons)
-c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1")
expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons
operator: a logical or comparison operator:

View File

@ -236,7 +236,7 @@ infolists: display infos about infolists
[-n] -c <expression1> <operator> <expression2>
-n: display result without sending it to buffer (debug mode)
-s: split expression (many commands can be separated by semicolons)
-s: split expression before evaluating it (many commands can be separated by semicolons)
-c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1")
expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons
operator: a logical or comparison operator:

View File

@ -236,7 +236,7 @@ infolists : afficher des infos sur les infolists
[-n] -c <expression1> <opérateur> <expression2>
-n : afficher le résultat sans envoyer au tampon (mode debug)
-s : découper l'expression (plusieurs commandes peuvent être séparées par des points-virgules)
-s : découper l'expression avant de l'évaluer (plusieurs commandes peuvent être séparées par des points-virgules)
-c : évaluer comme une condition : utiliser les opérateurs et les parenthèses, retourner une valeur booléenne ("0" ou "1")
expression : expression à évaluer, les variables avec le format ${variable} sont remplacées (voir ci-dessous) ; plusieurs commandes peuvent être séparées par des points-virgules
opérateur : un opérateur logique ou de comparaison :

View File

@ -236,7 +236,7 @@ infolists: display infos about infolists
[-n] -c <expression1> <operator> <expression2>
-n: display result without sending it to buffer (debug mode)
-s: split expression (many commands can be separated by semicolons)
-s: split expression before evaluating it (many commands can be separated by semicolons)
-c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1")
expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons
operator: a logical or comparison operator:

View File

@ -236,7 +236,7 @@ infolists: infolist に関する情報を表示
[-n] -c <expression1> <operator> <expression2>
-n: display result without sending it to buffer (debug mode)
-s: split expression (many commands can be separated by semicolons)
-s: split expression before evaluating it (many commands can be separated by semicolons)
-c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1")
expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons
operator: a logical or comparison operator:

View File

@ -236,7 +236,7 @@ infolists: wyświetla informacje o infolistach
[-n] -c <expression1> <operator> <expression2>
-n: display result without sending it to buffer (debug mode)
-s: split expression (many commands can be separated by semicolons)
-s: split expression before evaluating it (many commands can be separated by semicolons)
-c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1")
expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons
operator: a logical or comparison operator:

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1400,7 +1400,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -24,7 +24,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2015-01-25 18:35+0100\n"
"Last-Translator: Nils Görs <weechatter@arcor.de>\n"
"Language-Team: German <>\n"
@ -1478,7 +1478,8 @@ msgstr "[-n] <expression> || [-n] -c <expression1> <operator> <expression2>"
#, fuzzy
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1438,7 +1438,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"PO-Revision-Date: 2015-01-30 08:26+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2015-01-30 09:42+0100\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: fr\n"
@ -1450,7 +1450,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "
@ -1520,8 +1521,8 @@ msgid ""
" /eval -n -c abcd !~ abc ==> 0"
msgstr ""
" -n : afficher le résultat sans envoyer au tampon (mode debug)\n"
" -s : découper l'expression (plusieurs commandes peuvent être "
"séparées par des points-virgules)\n"
" -s : découper l'expression avant de l'évaluer (plusieurs commandes "
"peuvent être séparées par des points-virgules)\n"
" -c : évaluer comme une condition : utiliser les opérateurs et les "
"parenthèses, retourner une valeur booléenne (\"0\" ou \"1\")\n"
"expression : expression à évaluer, les variables avec le format ${variable} "

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1331,7 +1331,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Esteban I. Ruiz Moreno <exio4.com@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1420,7 +1420,8 @@ msgstr ""
#, fuzzy
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2015-01-25 13:54+0900\n"
"Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/weechat/tree/translation_ja>\n"
@ -1417,7 +1417,8 @@ msgstr "[-n] <expression> || [-n] -c <expression1> <operator> <expression2>"
#, fuzzy
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-12-26 19:51+0100\n"
"Last-Translator: Krzysztof Korościk <soltys@szluug.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1454,7 +1454,8 @@ msgstr "[-n] <wyrażenie> || [-n] -c <wyrażenie1> <operator> <wyrażenie2>"
#, fuzzy
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Sergio Durigan Junior <sergiosdj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1456,7 +1456,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-11-09 16:23+0100\n"
"Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1353,7 +1353,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-07-25 07:50+0200\n"
"Last-Translator: Hasan Kiran <sunder67@hotmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1188,7 +1188,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2015-01-30 08:25+0100\n"
"POT-Creation-Date: 2015-01-30 09:41+0100\n"
"PO-Revision-Date: 2014-08-16 10:27+0200\n"
"Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1190,7 +1190,8 @@ msgstr ""
msgid ""
" -n: display result without sending it to buffer (debug mode)\n"
" -s: split expression (many commands can be separated by semicolons)\n"
" -s: split expression before evaluating it (many commands can be "
"separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, return a "
"boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format ${variable} are "

View File

@ -1815,7 +1815,7 @@ COMMAND_CALLBACK(debug)
COMMAND_CALLBACK(eval)
{
int i, print_only, split_command, condition;
int i, print_only, split_command, condition, error;
char *result, *ptr_args, *expr, **commands;
struct t_hashtable *pointers, *options;
@ -1826,6 +1826,7 @@ COMMAND_CALLBACK(eval)
print_only = 0;
split_command = 0;
condition = 0;
error = 0;
COMMAND_MIN_ARGS(2, "");
@ -1880,7 +1881,6 @@ COMMAND_CALLBACK(eval)
hashtable_set (options, "type", "condition");
}
result = NULL;
if (print_only)
{
expr = string_remove_quotes (ptr_args, "\"");
@ -1895,6 +1895,7 @@ COMMAND_CALLBACK(eval)
GUI_COLOR(GUI_COLOR_CHAT),
result,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
free (result);
}
else
{
@ -1909,35 +1910,50 @@ COMMAND_CALLBACK(eval)
}
else
{
result = eval_expression (ptr_args, pointers, NULL, options);
if (result)
if (split_command)
{
if (split_command)
commands = string_split_command (ptr_args, ';');
if (commands)
{
commands = string_split_command (result, ';');
if (commands)
for (i = 0; commands[i]; i++)
{
for (i = 0; commands[i]; i++)
result = eval_expression (commands[i], pointers, NULL,
options);
if (result)
{
(void) input_data (buffer, commands[i]);
(void) input_data (buffer, result);
free (result);
}
else
{
error = 1;
}
string_free_split_command (commands);
}
}
else
{
(void) input_data (buffer, result);
string_free_split_command (commands);
}
}
else
{
gui_chat_printf (NULL,
_("%sError in expression to evaluate"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
result = eval_expression (ptr_args, pointers, NULL, options);
if (result)
{
(void) input_data (buffer, result);
free (result);
}
else
{
error = 1;
}
}
}
if (result)
free (result);
if (error)
{
gui_chat_printf (NULL,
_("%sError in expression to evaluate"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
}
if (pointers)
hashtable_free (pointers);
if (options)
@ -7122,8 +7138,8 @@ command_init ()
" || [-n] -c <expression1> <operator> <expression2>"),
N_(" -n: display result without sending it to buffer "
"(debug mode)\n"
" -s: split expression (many commands can be separated by "
"semicolons)\n"
" -s: split expression before evaluating it "
"(many commands can be separated by semicolons)\n"
" -c: evaluate as condition: use operators and parentheses, "
"return a boolean value (\"0\" or \"1\")\n"
"expression: expression to evaluate, variables with format "