diff options
-rw-r--r-- | ChangeLog.asciidoc | 2 | ||||
-rw-r--r-- | doc/de/autogen/user/weechat_commands.asciidoc | 103 | ||||
-rw-r--r-- | doc/en/autogen/user/weechat_commands.asciidoc | 19 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.asciidoc | 21 | ||||
-rw-r--r-- | doc/fr/autogen/user/weechat_commands.asciidoc | 19 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.asciidoc | 21 | ||||
-rw-r--r-- | doc/it/autogen/user/weechat_commands.asciidoc | 19 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.asciidoc | 23 | ||||
-rw-r--r-- | doc/ja/autogen/user/weechat_commands.asciidoc | 19 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.asciidoc | 24 | ||||
-rw-r--r-- | doc/pl/autogen/user/weechat_commands.asciidoc | 19 | ||||
-rw-r--r-- | po/cs.po | 24 | ||||
-rw-r--r-- | po/de.po | 25 | ||||
-rw-r--r-- | po/es.po | 24 | ||||
-rw-r--r-- | po/fr.po | 45 | ||||
-rw-r--r-- | po/hu.po | 24 | ||||
-rw-r--r-- | po/it.po | 24 | ||||
-rw-r--r-- | po/ja.po | 24 | ||||
-rw-r--r-- | po/pl.po | 24 | ||||
-rw-r--r-- | po/pt_BR.po | 24 | ||||
-rw-r--r-- | po/ru.po | 24 | ||||
-rw-r--r-- | po/tr.po | 24 | ||||
-rw-r--r-- | po/weechat.pot | 24 | ||||
-rw-r--r-- | src/core/wee-command.c | 19 | ||||
-rw-r--r-- | src/core/wee-eval.c | 88 | ||||
-rw-r--r-- | tests/unit/core/test-eval.cpp | 13 |
26 files changed, 457 insertions, 262 deletions
diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index fdda32e4b..74aa8a402 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -23,6 +23,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] (closes #452) * core: allow pointer as list name in evaluation of hdata (closes #450) * core: add signal "signal_sighup" +* api: add support of evaluated sub-strings and current date/time in function + string_eval_expression() and command /eval * api: add function string_eval_path_home() * logger: evaluate content of option logger.file.path (issue #388) * relay: display value of HTTP header "X-Real-IP" for websocket connections diff --git a/doc/de/autogen/user/weechat_commands.asciidoc b/doc/de/autogen/user/weechat_commands.asciidoc index de67f79cb..49fa3fc95 100644 --- a/doc/de/autogen/user/weechat_commands.asciidoc +++ b/doc/de/autogen/user/weechat_commands.asciidoc @@ -251,49 +251,51 @@ infolists: zeigt Information über die Infolists an /eval [-n|-s] <expression> [-n] -c <expression1> <operator> <expression2> - -n: gibt das Ergebnis aus, ohne das dieses in den Buffer gesendet wird (debug Modus) - -s: teilt Ausdrücke bevor sie evaluiert werden (mehrere Befehle können durch Semikolon getrennt werden) - -c: Auswertung als Bedingung: nutzt Operatoren und runde Klammern, Rückgabewert als Boolean-Wert ("0" oder "1") -expression: Ausdruck welcher verarbeitet werden soll. Variablen im Format ${variable} werden ersetzt (siehe unten); mehrere Befehle werden durch ein Semikolon voneinander getrennt - operator: ein logischer oder vergleichender Operand: - - logische Operanden: - && boolean "und" - || boolean "oder" - - vergleichende Operanden: - == gleich - != ungleich - <= kleiner oder gleich - < kleiner - >= größer oder gleich - > größer - =~ stimmt mit regulärem POSIX Ausdruck überein - !~ stimmt NICHT mit regulärem POSIX Ausdruck überein - -Ein Ausdruck gilt als "wahr", sofern das Ergebnis nicht NULL, nicht leer und von "0" abweichend ist. -Der Vergleich findet zwischen zwei Integer Werten statt, sofern die beiden Ausdrücke gültige Integer-Werte sind. -Um einen Vergleich zwischen zwei Zeichenketten zu erzwingen, müssen die Ausdrücke in Anführungszeichen gesetzt werden, zum Beispiel: + -n: display result without sending it to buffer (debug mode) + -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: + - logical operators: + && boolean "and" + || boolean "or" + - comparison operators: + == equal + != not equal + <= less or equal + < less + >= greater or equal + > greater + =~ is matching POSIX extended regex + !~ is NOT matching POSIX extended regex + +An expression is considered as "true" if it is not NULL, not empty, and different from "0". +The comparison is made using integers if the two expressions are valid integers. +To force a string comparison, add double quotes around each expression, for example: 50 > 100 ==> 0 "50" > "100" ==> 1 -Einige Variablen werden im Ausdruck, mittels der Formatierung ${Variable}, ersetzt. Mögliche Variablen sind, nach Reihenfolge ihrer Priorität: - 1. eine Zeichenkette mit Escapesequenzen (Format: "esc:xxx" oder "\xxx") - 2. Zeichen welche in einer Zeichenkette nicht dargestellt werden sollen (Format: "hide:Zeichen,Zeichenkette") - 3. eine Farbe (Format: color:xxx) - 4. eine Info (Format: "info:name,arguments", Argumente sind optional) - 5. eine Umgebungsvariable (Format: "env:XXX") - 6. der Name einer Programmoption (Format: file.section.option) - 7. der Name einer lokalen Variablen eines Buffer - 8. ein hdata Name/Variable (der Wert wird automatisch als Zeichenkette konvertiert), standardmäßig wird für "window" und "buffer" das aktuelle Fenster/Buffer verwendet. -Das Format für hdata kann wie folgt aufgebaut sein: - hdata.var1.var2...: startet mit hdata (der Pointer muss bekannt sein) und fragt eine Variable nach der anderen ab (weitere hdata können folgen) - hdata[list].var1.var2...: startet hdata mittels einer Liste, zum Beispiel: - ${buffer[gui_buffers].full_name}: der vollständige Name des ersten Buffers, in der verknüpften Liste aller Buffer - ${plugin[weechat_plugins].name}: Name der ersten Erweiterung, in der verknüpften Liste aller Erweiterungen - hdata[pointer].var1.var2...: startet hdata mittels einem Pointer, zum Beispiel: - ${buffer[0x1234abcd].full_name}: vollständiger Name eines Buffers und des dazugehörigen Pointers (kann in triggern benutzt werden) -Die vorhandenen Namen für hdata und Variablen sind in der "Anleitung für API Erweiterung", Bereich "weechat_hdata_get". beschrieben - -Beispiele (einfache Zeichenketten): +Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a color (format: "color:xxx") + 5. an info (format: "info:name,arguments", arguments are optional) + 6. current date/time (format: "date" or "date:format") + 7. an environment variable (format: "env:XXX") + 8. an option (format: "file.section.option") + 9. a local variable in buffer + 10. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. +Format for hdata can be one of following: + hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) + hdata[list].var1.var2...: start with a hdata using a list, for example: + ${buffer[gui_buffers].full_name}: full name of first buffer in linked list of buffers + ${plugin[weechat_plugins].name}: name of first plugin in linked list of plugins + hdata[pointer].var1.var2...: start with a hdata using a pointer, for example: + ${buffer[0x1234abcd].full_name}: full name of the buffer with this pointer (can be used in triggers) +For name of hdata and variables, please look at "Plugin API reference", function "weechat_hdata_get". + +Examples (simple strings): /eval -n ${info:version} ==> 0.4.3 /eval -n ${env:HOME} ==> /home/user /eval -n ${weechat.look.scroll_amount} ==> 3 @@ -303,16 +305,17 @@ Beispiele (einfache Zeichenketten): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- - -Beispiele (Bedingungen): - /eval -n -c ${window.buffer.number} > 2 ==> 0 - /eval -n -c ${window.win_width} > 100 ==> 1 - /eval -n -c (8 > 12) || (5 > 2) ==> 1 - /eval -n -c (8 > 12) && (5 > 2) ==> 0 - /eval -n -c abcd =~ ^ABC ==> 1 - /eval -n -c abcd =~ (?-i)^ABC ==> 0 - /eval -n -c abcd =~ (?-i)^abc ==> 1 - /eval -n -c abcd !~ abc ==> 0 + /eval -n ${date:%H:%M:%S} ==> 07:46:40 + +Examples (conditions): + /eval -n -c ${window.buffer.number} > 2 ==> 0 + /eval -n -c ${window.win_width} > 100 ==> 1 + /eval -n -c (8 > 12) || (5 > 2) ==> 1 + /eval -n -c (8 > 12) && (5 > 2) ==> 0 + /eval -n -c abcd =~ ^ABC ==> 1 + /eval -n -c abcd =~ (?-i)^ABC ==> 0 + /eval -n -c abcd =~ (?-i)^abc ==> 1 + /eval -n -c abcd !~ abc ==> 0 ---- [[command_weechat_filter]] diff --git a/doc/en/autogen/user/weechat_commands.asciidoc b/doc/en/autogen/user/weechat_commands.asciidoc index 9ff20bc01..aea0caa96 100644 --- a/doc/en/autogen/user/weechat_commands.asciidoc +++ b/doc/en/autogen/user/weechat_commands.asciidoc @@ -276,14 +276,16 @@ To force a string comparison, add double quotes around each expression, for exam "50" > "100" ==> 1 Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: - 1. a string with escaped chars (format: "esc:xxx" or "\xxx") - 2. a string with chars to hide (format: "hide:char,string") - 3. a color (format: "color:xxx") - 4. an info (format: "info:name,arguments", arguments are optional) - 5. an environment variable (format: "env:XXX") - 6. an option (format: "file.section.option") - 7. a local variable in buffer - 8. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a color (format: "color:xxx") + 5. an info (format: "info:name,arguments", arguments are optional) + 6. current date/time (format: "date" or "date:format") + 7. an environment variable (format: "env:XXX") + 8. an option (format: "file.section.option") + 9. a local variable in buffer + 10. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. Format for hdata can be one of following: hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) hdata[list].var1.var2...: start with a hdata using a list, for example: @@ -303,6 +305,7 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- + /eval -n ${date:%H:%M:%S} ==> 07:46:40 Examples (conditions): /eval -n -c ${window.buffer.number} > 2 ==> 0 diff --git a/doc/en/weechat_plugin_api.en.asciidoc b/doc/en/weechat_plugin_api.en.asciidoc index cca10ff35..369d62782 100644 --- a/doc/en/weechat_plugin_api.en.asciidoc +++ b/doc/en/weechat_plugin_api.en.asciidoc @@ -1902,7 +1902,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test" ==== string_eval_expression -_WeeChat ≥ 0.4.0, updated in 0.4.2 and 1.1._ +_WeeChat ≥ 0.4.0, updated in 0.4.2, 1.0, 1.1, 1.2 and 1.3._ Evaluate an expression and return result as a string. Special variables with format `${variable}` are expanded (see table below). @@ -1954,13 +1954,20 @@ Return value: List of variables expanded in expression (by order of priority, from first expanded to last): -[width="100%",cols="2,8,3,3",options="header"] +[width="100%",cols="2,8,4,4",options="header"] |=== | Format | Description | Examples | Results | `${name}` | Variable `name` from hashtable 'extra_vars' | `${name}` | `value` +| `${eval:xxx}` + + (_WeeChat ≥ 1.3_) | + String to evaluate | + `${eval:${date:${weechat.look.buffer_time_format}}}` | + `19:02:45` (with colors if there are color codes in the option + weechat.look.buffer_time_format) + | `${esc:xxx}` + `${\xxx}` | String with escaped chars | `${esc:prefix\tmessage}` + @@ -1996,6 +2003,16 @@ expanded to last): `1.0` + `lightblue` +| `${date}` + + `${date:xxx}` + + (_WeeChat ≥ 1.3_) | + Current date/time, with custom format (see `man strftime`), + default format is `%F %T` | + `${date}` + + `${date:%H:%M:%S}` | + `2015-06-30 19:02:45` + + `19:02:45` + | `${env:NAME}` + (_WeeChat ≥ 1.2_) | Value of the environment variable `NAME` | diff --git a/doc/fr/autogen/user/weechat_commands.asciidoc b/doc/fr/autogen/user/weechat_commands.asciidoc index 967e4b2ba..c5aca48ca 100644 --- a/doc/fr/autogen/user/weechat_commands.asciidoc +++ b/doc/fr/autogen/user/weechat_commands.asciidoc @@ -276,14 +276,16 @@ Pour forcer une comparaison de chaînes, ajoutez des guillemets autour de chaque "50" > "100" ==> 1 Des variables sont remplacées dans l'expression, en utilisant le format ${variable}, la variable pouvant être, par ordre de priorité : - 1. une chaîne avec les caractères échappés (format : "esc:xxx" ou "\xxx") - 2. une chaîne avec des caractères à cacher (format : "hide:caractère,chaîne") - 3. une couleur (format : "color:xxx") - 4. une info (format : "info:nom,paramètres", les paramètres sont optionnels) - 5. une variable d'environnement (format : "env:XXX") - 6. une option (format : "fichier.section.option") - 7. une variable locale du tampon - 8. un hdata/variable (la valeur est automatiquement convertie en chaîne), par défaut "window" et "buffer" pointent vers la fenêtre et le tampon courants. + 1. une sous-chaîne évaluée (format : "eval:xxx") + 2. une chaîne avec les caractères échappés (format : "esc:xxx" ou "\xxx") + 3. une chaîne avec des caractères à cacher (format : "hide:caractère,chaîne") + 4. une couleur (format : "color:xxx") + 5. une info (format : "info:nom,paramètres", les paramètres sont optionnels) + 6. la date/heure courante (format : "date" ou "date:format") + 7. une variable d'environnement (format : "env:XXX") + 8. une option (format : "fichier.section.option") + 9. une variable locale du tampon + 10. un hdata/variable (la valeur est automatiquement convertie en chaîne), par défaut "window" et "buffer" pointent vers la fenêtre et le tampon courants. Le format du hdata peut être le suivant : hdata.var1.var2... : démarrer avec un hdata (le pointeur doit être connu), et demander les variables l'une après l'autre (d'autres hdata peuvent être suivis) hdata[liste].var1.var2... : démarrer avec un hdata en utilisant une liste, par exemple : @@ -303,6 +305,7 @@ Exemples (chaînes simples) : /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- + /eval -n ${date:%H:%M:%S} ==> 07:46:40 Exemples (conditions) : /eval -n -c ${window.buffer.number} > 2 ==> 0 diff --git a/doc/fr/weechat_plugin_api.fr.asciidoc b/doc/fr/weechat_plugin_api.fr.asciidoc index 026c1da74..8baf089d8 100644 --- a/doc/fr/weechat_plugin_api.fr.asciidoc +++ b/doc/fr/weechat_plugin_api.fr.asciidoc @@ -1935,7 +1935,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test" ==== string_eval_expression -_WeeChat ≥ 0.4.0, mis à jour dans la 0.4.2 et 1.1._ +_WeeChat ≥ 0.4.0, mis à jour dans la 0.4.2, 1.0, 1.1, 1.2 et 1.3._ Évaluer l'expression et retourner le résultat sous forme de chaîne. Les variables spéciales avec le format `${variable}` sont étendues (voir le @@ -1993,13 +1993,20 @@ Valeur de retour : Liste des variables étendues dans l'expression (par ordre de priorité, de la première étendue à la dernière) : -[width="100%",cols="2,8,3,3",options="header"] +[width="100%",cols="2,8,4,4",options="header"] |=== | Format | Description | Exemples | Résultats | `${nom}` | Variable `nom` de la table de hachage 'extra_vars' | `${nom}` | `valeur` +| `${eval:xxx}` + + (_WeeChat ≥ 1.3_) | + Chaîne à évaluer | + `${eval:${date:${weechat.look.buffer_time_format}}}` | + `19:02:45` (avec des couleurs s'il y a des codes couleur dans l'option + weechat.look.buffer_time_format) + | `${esc:xxx}` + `${\xxx}` | Chaîne avec caractères échappés | `${esc:préfixe\tmessage}` + @@ -2036,6 +2043,16 @@ première étendue à la dernière) : `1.0` + `lightblue` +| `${date}` + + `${date:xxx}` + + (_WeeChat ≥ 1.3_) | + La date/heure courante, avec un format personnalisé (voir `man strftime`), + le format par défaut est `%F %T` | + `${date}` + + `${date:%H:%M:%S}` | + `2015-06-30 19:02:45` + + `19:02:45` + | `${env:NOM}` + (_WeeChat ≥ 1.2_) | Valeur de la variable d'environnement `NOM` | diff --git a/doc/it/autogen/user/weechat_commands.asciidoc b/doc/it/autogen/user/weechat_commands.asciidoc index 6933ccffa..f416f591e 100644 --- a/doc/it/autogen/user/weechat_commands.asciidoc +++ b/doc/it/autogen/user/weechat_commands.asciidoc @@ -276,14 +276,16 @@ To force a string comparison, add double quotes around each expression, for exam "50" > "100" ==> 1 Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: - 1. a string with escaped chars (format: "esc:xxx" or "\xxx") - 2. a string with chars to hide (format: "hide:char,string") - 3. a color (format: "color:xxx") - 4. an info (format: "info:name,arguments", arguments are optional) - 5. an environment variable (format: "env:XXX") - 6. an option (format: "file.section.option") - 7. a local variable in buffer - 8. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a color (format: "color:xxx") + 5. an info (format: "info:name,arguments", arguments are optional) + 6. current date/time (format: "date" or "date:format") + 7. an environment variable (format: "env:XXX") + 8. an option (format: "file.section.option") + 9. a local variable in buffer + 10. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. Format for hdata can be one of following: hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) hdata[list].var1.var2...: start with a hdata using a list, for example: @@ -303,6 +305,7 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- + /eval -n ${date:%H:%M:%S} ==> 07:46:40 Examples (conditions): /eval -n -c ${window.buffer.number} > 2 ==> 0 diff --git a/doc/it/weechat_plugin_api.it.asciidoc b/doc/it/weechat_plugin_api.it.asciidoc index 9cbac6eca..9f148893f 100644 --- a/doc/it/weechat_plugin_api.it.asciidoc +++ b/doc/it/weechat_plugin_api.it.asciidoc @@ -1967,7 +1967,7 @@ str3 = weechat.string_input_for_buffer("//test") # "/test" ==== string_eval_expression // TRANSLATION MISSING -_WeeChat ≥ 0.4.0, updated in 0.4.2 and 1.1._ +_WeeChat ≥ 0.4.0, updated in 0.4.2, 1.0, 1.1, 1.2 and 1.3._ // TRANSLATION MISSING Evaluate an expression and return result as a string. @@ -2025,13 +2025,21 @@ List of variables expanded in expression (by order of priority, from first expanded to last): // TRANSLATION MISSING -[width="100%",cols="2,8,3,3",options="header"] +[width="100%",cols="2,8,4,4",options="header"] |=== | Format | Description | Examples | Results | `${name}` | Variable `name` from hashtable 'extra_vars' | `${name}` | `value` +// TRANSLATION MISSING +| `${eval:xxx}` + + (_WeeChat ≥ 1.3_) | + String to evaluate | + `${eval:${date:${weechat.look.buffer_time_format}}}` | + `19:02:45` (with colors if there are color codes in the option + weechat.look.buffer_time_format) + | `${esc:xxx}` + `${\xxx}` | String with escaped chars | `${esc:prefix\tmessage}` + @@ -2067,6 +2075,17 @@ expanded to last): `1.0` + `lightblue` +// TRANSLATION MISSING +| `${date}` + + `${date:xxx}` + + (_WeeChat ≥ 1.3_) | + Current date/time, with custom format (see `man strftime`), + default format is `%F %T` | + `${date}` + + `${date:%H:%M:%S}` | + `2015-06-30 19:02:45` + + `19:02:45` + | `${env:NAME}` + (_WeeChat ≥ 1.2_) | Value of the environment variable `NAME` | diff --git a/doc/ja/autogen/user/weechat_commands.asciidoc b/doc/ja/autogen/user/weechat_commands.asciidoc index b72545ef6..ab7ab3d0d 100644 --- a/doc/ja/autogen/user/weechat_commands.asciidoc +++ b/doc/ja/autogen/user/weechat_commands.asciidoc @@ -276,14 +276,16 @@ To force a string comparison, add double quotes around each expression, for exam "50" > "100" ==> 1 Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: - 1. a string with escaped chars (format: "esc:xxx" or "\xxx") - 2. a string with chars to hide (format: "hide:char,string") - 3. a color (format: "color:xxx") - 4. an info (format: "info:name,arguments", arguments are optional) - 5. an environment variable (format: "env:XXX") - 6. an option (format: "file.section.option") - 7. a local variable in buffer - 8. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a color (format: "color:xxx") + 5. an info (format: "info:name,arguments", arguments are optional) + 6. current date/time (format: "date" or "date:format") + 7. an environment variable (format: "env:XXX") + 8. an option (format: "file.section.option") + 9. a local variable in buffer + 10. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. Format for hdata can be one of following: hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) hdata[list].var1.var2...: start with a hdata using a list, for example: @@ -303,6 +305,7 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- + /eval -n ${date:%H:%M:%S} ==> 07:46:40 Examples (conditions): /eval -n -c ${window.buffer.number} > 2 ==> 0 diff --git a/doc/ja/weechat_plugin_api.ja.asciidoc b/doc/ja/weechat_plugin_api.ja.asciidoc index 091018eba..66035ba09 100644 --- a/doc/ja/weechat_plugin_api.ja.asciidoc +++ b/doc/ja/weechat_plugin_api.ja.asciidoc @@ -1906,7 +1906,8 @@ str3 = weechat.string_input_for_buffer("//test") # "/test" ==== string_eval_expression -_WeeChat バージョン 0.4.0 以上で利用可、バージョン 0.4.2 と 1.1 で更新。_ +// TRANSLATION MISSING +_WeeChat ≥ 0.4.0, updated in 0.4.2, 1.0, 1.1, 1.2 and 1.3._ 式を評価して文字列として返す。`${variable}` という書式で書かれた特殊変数は展開されます (以下の表を参照)。 @@ -1958,13 +1959,21 @@ char *weechat_string_eval_expression (const char *expr, 式中で展開される変数のリスト (優先度の高い順、展開順の早いものを上に遅いものを下に): -[width="100%",cols="2,8,3,3",options="header"] +[width="100%",cols="2,8,4,4",options="header"] |=== | フォーマット | 説明 | 例 | 結果 | `${name}` | 'extra_vars' の変数 `name` の値に展開 | `${name}` | `value` +// TRANSLATION MISSING +| `${eval:xxx}` + + (_WeeChat ≥ 1.3_) | + String to evaluate | + `${eval:${date:${weechat.look.buffer_time_format}}}` | + `19:02:45` (with colors if there are color codes in the option + weechat.look.buffer_time_format) + | `${esc:xxx}` + `${\xxx}` | エスケープ文字を含む文字列 | `${esc:prefix\tmessage}` + @@ -2000,6 +2009,17 @@ char *weechat_string_eval_expression (const char *expr, `1.0` + `lightblue` +// TRANSLATION MISSING +| `${date}` + + `${date:xxx}` + + (_WeeChat ≥ 1.3_) | + Current date/time, with custom format (see `man strftime`), + default format is `%F %T` | + `${date}` + + `${date:%H:%M:%S}` | + `2015-06-30 19:02:45` + + `19:02:45` + | `${env:NAME}` + (_WeeChat バージョン 1.2 以上で利用可_) | Value of the environment variable `NAME` | diff --git a/doc/pl/autogen/user/weechat_commands.asciidoc b/doc/pl/autogen/user/weechat_commands.asciidoc index 0d2c93511..65ee1af9b 100644 --- a/doc/pl/autogen/user/weechat_commands.asciidoc +++ b/doc/pl/autogen/user/weechat_commands.asciidoc @@ -276,14 +276,16 @@ To force a string comparison, add double quotes around each expression, for exam "50" > "100" ==> 1 Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: - 1. a string with escaped chars (format: "esc:xxx" or "\xxx") - 2. a string with chars to hide (format: "hide:char,string") - 3. a color (format: "color:xxx") - 4. an info (format: "info:name,arguments", arguments are optional) - 5. an environment variable (format: "env:XXX") - 6. an option (format: "file.section.option") - 7. a local variable in buffer - 8. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a color (format: "color:xxx") + 5. an info (format: "info:name,arguments", arguments are optional) + 6. current date/time (format: "date" or "date:format") + 7. an environment variable (format: "env:XXX") + 8. an option (format: "file.section.option") + 9. a local variable in buffer + 10. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. Format for hdata can be one of following: hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) hdata[list].var1.var2...: start with a hdata using a list, for example: @@ -303,6 +305,7 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> <tab> /eval -n ${hide:-,${relay.network.password}} ==> -------- + /eval -n ${date:%H:%M:%S} ==> 07:46:40 Examples (conditions): /eval -n -c ${window.buffer.number} > 2 ==> 0 @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1468,15 +1468,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1502,6 +1505,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -24,7 +24,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-06-26 23:27+0100\n" "Last-Translator: Nils Görs <weechatter@arcor.de>\n" "Language-Team: German <>\n" @@ -1544,6 +1544,7 @@ msgstr "evaluierter Ausdruck" msgid "[-n|-s] <expression> || [-n] -c <expression1> <operator> <expression2>" msgstr "[-n|-s] <expression> || [-n] -c <expression1> <operator> <expression2>" +#, fuzzy msgid "" " -n: display result without sending it to buffer (debug mode)\n" " -s: split expression before evaluating it (many commands can be " @@ -1577,15 +1578,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1611,6 +1615,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1507,15 +1507,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1541,6 +1544,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" -"PO-Revision-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" +"PO-Revision-Date: 2015-06-30 07:50+0200\n" "Last-Translator: Sébastien Helleu <flashcode@flashtux.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" "Language: fr\n" @@ -1549,15 +1549,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1583,6 +1586,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -1628,17 +1632,19 @@ msgstr "" "\n" "Des variables sont remplacées dans l'expression, en utilisant le format " "${variable}, la variable pouvant être, par ordre de priorité :\n" -" 1. une chaîne avec les caractères échappés (format : \"esc:xxx\" ou \"\\xxx" +" 1. une sous-chaîne évaluée (format : \"eval:xxx\")\n" +" 2. une chaîne avec les caractères échappés (format : \"esc:xxx\" ou \"\\xxx" "\")\n" -" 2. une chaîne avec des caractères à cacher (format : \"hide:caractère," +" 3. une chaîne avec des caractères à cacher (format : \"hide:caractère," "chaîne\")\n" -" 3. une couleur (format : \"color:xxx\")\n" -" 4. une info (format : \"info:nom,paramètres\", les paramètres sont " +" 4. une couleur (format : \"color:xxx\")\n" +" 5. une info (format : \"info:nom,paramètres\", les paramètres sont " "optionnels)\n" -" 5. une variable d'environnement (format : \"env:XXX\")\n" -" 6. une option (format : \"fichier.section.option\")\n" -" 7. une variable locale du tampon\n" -" 8. un hdata/variable (la valeur est automatiquement convertie en chaîne), " +" 6. la date/heure courante (format : \"date\" ou \"date:format\")\n" +" 7. une variable d'environnement (format : \"env:XXX\")\n" +" 8. une option (format : \"fichier.section.option\")\n" +" 9. une variable locale du tampon\n" +" 10. un hdata/variable (la valeur est automatiquement convertie en chaîne), " "par défaut \"window\" et \"buffer\" pointent vers la fenêtre et le tampon " "courants.\n" "Le format du hdata peut être le suivant :\n" @@ -1668,6 +1674,7 @@ msgstr "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Exemples (conditions) :\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1399,15 +1399,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1433,6 +1436,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Esteban I. Ruiz Moreno <exio4.com@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1490,15 +1490,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1524,6 +1527,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-06-21 22:54+0900\n" "Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n" "Language-Team: Japanese <https://github.com/l/weechat/tree/translation_ja>\n" @@ -1514,15 +1514,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1548,6 +1551,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-05-09 14:00+0100\n" "Last-Translator: Krzysztof Korościk <soltys@szluug.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1550,15 +1550,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1584,6 +1587,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" diff --git a/po/pt_BR.po b/po/pt_BR.po index abade822f..9f077604e 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Eduardo Elias <camponez@gmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1552,15 +1552,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1586,6 +1589,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-21 08:41+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1421,15 +1421,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1455,6 +1458,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\n" "PO-Revision-Date: 2015-03-10 21:33+0100\n" "Last-Translator: Hasan Kiran <sunder67@hotmail.com>\n" "Language-Team: weechat-dev <weechat-dev@nongnu.org>\n" @@ -1256,15 +1256,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1290,6 +1293,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" diff --git a/po/weechat.pot b/po/weechat.pot index a05dd7857..eac02c5c3 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2015-06-28 09:11+0200\n" +"POT-Creation-Date: 2015-06-30 07:49+0200\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" @@ -1258,15 +1258,18 @@ msgid "" "\n" "Some variables are replaced in expression, using the format ${variable}, " "variable can be, by order of priority:\n" -" 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" -" 2. a string with chars to hide (format: \"hide:char,string\")\n" -" 3. a color (format: \"color:xxx\")\n" -" 4. an info (format: \"info:name,arguments\", arguments are optional)\n" -" 5. an environment variable (format: \"env:XXX\")\n" -" 6. an option (format: \"file.section.option\")\n" -" 7. a local variable in buffer\n" -" 8. a hdata name/variable (the value is automatically converted to string), " -"by default \"window\" and \"buffer\" point to current window/buffer.\n" +" 1. an evaluated sub-string (format: \"eval:xxx\")\n" +" 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" +" 3. a string with chars to hide (format: \"hide:char,string\")\n" +" 4. a color (format: \"color:xxx\")\n" +" 5. an info (format: \"info:name,arguments\", arguments are optional)\n" +" 6. current date/time (format: \"date\" or \"date:format\")\n" +" 7. an environment variable (format: \"env:XXX\")\n" +" 8. an option (format: \"file.section.option\")\n" +" 9. a local variable in buffer\n" +" 10. 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" " hdata.var1.var2...: start with a hdata (pointer must be known), and ask " "variables one after one (other hdata can be followed)\n" @@ -1292,6 +1295,7 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" +" /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index f8e7032e4..aece0e78a 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -7190,15 +7190,17 @@ command_init () "\n" "Some variables are replaced in expression, using the format " "${variable}, variable can be, by order of priority:\n" - " 1. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" - " 2. a string with chars to hide (format: \"hide:char,string\")\n" - " 3. a color (format: \"color:xxx\")\n" - " 4. an info (format: \"info:name,arguments\", arguments are " + " 1. an evaluated sub-string (format: \"eval:xxx\")\n" + " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" + " 3. a string with chars to hide (format: \"hide:char,string\")\n" + " 4. a color (format: \"color:xxx\")\n" + " 5. an info (format: \"info:name,arguments\", arguments are " "optional)\n" - " 5. an environment variable (format: \"env:XXX\")\n" - " 6. an option (format: \"file.section.option\")\n" - " 7. a local variable in buffer\n" - " 8. a hdata name/variable (the value is automatically converted " + " 6. current date/time (format: \"date\" or \"date:format\")\n" + " 7. an environment variable (format: \"env:XXX\")\n" + " 8. an option (format: \"file.section.option\")\n" + " 9. a local variable in buffer\n" + " 10. 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" @@ -7227,6 +7229,7 @@ command_init () " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> <tab>\n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" + " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" "\n" "Examples (conditions):\n" " /eval -n -c ${window.buffer.number} > 2 ==> 0\n" diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 105068d89..ecc2abd27 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> #include <regex.h> +#include <time.h> #include "weechat.h" #include "wee-eval.h" @@ -48,7 +49,10 @@ char *logical_ops[EVAL_NUM_LOGICAL_OPS] = char *comparisons[EVAL_NUM_COMPARISONS] = { "=~", "!~", "==", "!=", "<=", "<", ">=", ">" }; -struct t_hashtable *eval_hashtable_pointers = NULL; +char *eval_replace_vars (const char *expr, struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + const char *prefix, const char *suffix, + struct t_eval_regex *eval_regex); /* @@ -221,19 +225,20 @@ end: /* * Replaces variables, which can be, by order of priority: * 1. an extra variable from hashtable "extra_vars" - * 2. a string with escaped chars (format: esc:xxx or \xxx) - * 3. a string with chars to hide (format: hide:char,string) - * 4. a regex group captured (format: re:N (0.99) or re:+) - * 5. a color (format: color:xxx) - * 6. an info (format: info:name,arguments) - * 7. an option (format: file.section.option) - * 8. a buffer local variable - * 9. a hdata variable (format: hdata.var1.var2 or hdata[list].var1.var2) + * 2. a string to evaluate (format: eval:xxx) + * 3. a string with escaped chars (format: esc:xxx or \xxx) + * 4. a string with chars to hide (format: hide:char,string) + * 5. a regex group captured (format: re:N (0.99) or re:+) + * 6. a color (format: color:xxx) + * 7. an info (format: info:name,arguments) + * 8. current date/time (format: date or date:xxx) + * 9. an environment variable (format: env:XXX) + * 10. an option (format: file.section.option) + * 11. a buffer local variable + * 12. a hdata variable (format: hdata.var1.var2 or hdata[list].var1.var2 + * or hdata[ptr].var1.var2) * - * Examples: - * option: ${weechat.look.scroll_amount} - * hdata : ${window.buffer.full_name} - * ${window.buffer.local_variables.type} + * See /help in WeeChat for examples. */ char * @@ -243,18 +248,22 @@ eval_replace_vars_cb (void *data, const char *text) struct t_eval_regex *eval_regex; struct t_config_option *ptr_option; struct t_gui_buffer *ptr_buffer; - char str_value[64], *value, *pos, *pos1, *pos2, *hdata_name, *list_name; + char str_value[512], *value, *pos, *pos1, *pos2, *hdata_name, *list_name; char *tmp, *info_name, *hide_char, *hidden_string, *error; - const char *ptr_value, *ptr_arguments, *ptr_string; + const char *prefix, *suffix, *ptr_value, *ptr_arguments, *ptr_string; struct t_hdata *hdata; void *pointer; int i, length_hide_char, length, index, rc; long number; long unsigned int ptr; + time_t date; + struct tm *date_tmp; pointers = (struct t_hashtable *)(((void **)data)[0]); extra_vars = (struct t_hashtable *)(((void **)data)[1]); - eval_regex = (struct t_eval_regex *)(((void **)data)[2]); + prefix = (const char *)(((void **)data)[2]); + suffix = (const char *)(((void **)data)[3]); + eval_regex = (struct t_eval_regex *)(((void **)data)[4]); /* 1. variable in hashtable "extra_vars" */ if (extra_vars) @@ -264,13 +273,23 @@ eval_replace_vars_cb (void *data, const char *text) return strdup (ptr_value); } - /* 2. convert escaped chars */ + /* + * 2. force evaluation of string (recursive call) + * --> use with caution: the text must be safe! + */ + if (strncmp (text, "eval:", 5) == 0) + { + return eval_replace_vars (text + 5, pointers, extra_vars, + prefix, suffix, eval_regex); + } + + /* 3. 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. hide chars: replace all chars by a given char/string */ + /* 4. hide chars: replace all chars by a given char/string */ if (strncmp (text, "hide:", 5) == 0) { hidden_string = NULL; @@ -300,7 +319,7 @@ eval_replace_vars_cb (void *data, const char *text) return (hidden_string) ? hidden_string : strdup (""); } - /* 4. regex group captured */ + /* 5. regex group captured */ if (strncmp (text, "re:", 3) == 0) { if (eval_regex && eval_regex->result) @@ -323,7 +342,7 @@ eval_replace_vars_cb (void *data, const char *text) return strdup (""); } - /* 5. color code */ + /* 6. color code */ if (strncmp (text, "color:", 6) == 0) { ptr_value = gui_color_search_config (text + 6); @@ -333,7 +352,7 @@ eval_replace_vars_cb (void *data, const char *text) return strdup ((ptr_value) ? ptr_value : ""); } - /* 6. info */ + /* 7. info */ if (strncmp (text, "info:", 5) == 0) { ptr_value = NULL; @@ -353,7 +372,20 @@ eval_replace_vars_cb (void *data, const char *text) return strdup ((ptr_value) ? ptr_value : ""); } - /* 7. environment variable */ + /* 8. current date/time */ + if ((strncmp (text, "date", 4) == 0) && (!text[4] || (text[4] == ':'))) + { + date = time (NULL); + date_tmp = localtime (&date); + if (!date_tmp) + return strdup (""); + rc = (int) strftime (str_value, sizeof (str_value), + (text[4] == ':') ? text + 5 : "%F %T", + date_tmp); + return strdup ((rc > 0) ? str_value : ""); + } + + /* 9. environment variable */ if (strncmp (text, "env:", 4) == 0) { ptr_value = getenv (text + 4); @@ -361,7 +393,7 @@ eval_replace_vars_cb (void *data, const char *text) return strdup (ptr_value); } - /* 8. option: if found, return this value */ + /* 10. option: if found, return this value */ if (strncmp (text, "sec.data.", 9) == 0) { ptr_value = hashtable_get (secure_hashtable_data, text + 9); @@ -394,7 +426,7 @@ eval_replace_vars_cb (void *data, const char *text) } } - /* 9. local variable in buffer */ + /* 11. local variable in buffer */ ptr_buffer = hashtable_get (pointers, "buffer"); if (ptr_buffer) { @@ -403,7 +435,7 @@ eval_replace_vars_cb (void *data, const char *text) return strdup (ptr_value); } - /* 10. hdata */ + /* 12. hdata */ value = NULL; hdata_name = NULL; list_name = NULL; @@ -486,11 +518,13 @@ eval_replace_vars (const char *expr, struct t_hashtable *pointers, const char *prefix, const char *suffix, struct t_eval_regex *eval_regex) { - void *ptr[3]; + const void *ptr[5]; ptr[0] = pointers; ptr[1] = extra_vars; - ptr[2] = eval_regex; + ptr[2] = prefix; + ptr[3] = suffix; + ptr[4] = eval_regex; return string_replace_with_callback (expr, prefix, suffix, &eval_replace_vars_cb, ptr, NULL); diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp index 39deb4e0c..8b938e00a 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-eval.cpp @@ -24,6 +24,7 @@ extern "C" { #include <stdio.h> +#include <string.h> #include <regex.h> #include "src/core/wee-eval.h" #include "src/core/wee-config.h" @@ -198,6 +199,9 @@ TEST(Eval, EvalExpression) WEE_CHECK_EVAL("", "${}"); WEE_CHECK_EVAL("", "${xyz}"); + /* test eval of substring */ + WEE_CHECK_EVAL("\t", "${eval:${\\t}}"); + /* test value from extra_vars */ WEE_CHECK_EVAL("value", "${test}"); @@ -230,6 +234,15 @@ TEST(Eval, EvalExpression) /* test info */ WEE_CHECK_EVAL(version_get_version (), "${info:version}"); + /* test date */ + value = eval_expression ("${date}", pointers, extra_vars, options); + LONGS_EQUAL(19, strlen (value)); + free (value); + value = eval_expression ("${date:%H:%M:%S}", + pointers, extra_vars, options); + LONGS_EQUAL(8, strlen (value)); + free (value); + /* test option */ snprintf (str_value, sizeof (str_value), "%d", CONFIG_INTEGER(config_look_scroll_amount)); |