From 009925b9ac9fc280a1bb30d7aa64db6777d0ac43 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 24 Jan 2012 19:02:06 +0100 Subject: [PATCH] api: add modifier "input_text_for_buffer" --- ChangeLog | 1 + doc/en/weechat_plugin_api.en.txt | 26 ++++++---- doc/fr/weechat_plugin_api.fr.txt | 30 +++++++---- doc/it/weechat_plugin_api.it.txt | 33 ++++++++---- src/core/wee-input.c | 88 ++++++++++++++++++-------------- 5 files changed, 110 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebd6ad711..4a8f0028f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,6 +42,7 @@ Version 0.3.7 (under dev!) * core: fix compilation error with "pid_t" on Mac OS X (bug #34639) * core: enable background process under Cygwin to connect to servers, fix reconnection problem (bug #34626) +* api: add modifier "input_text_for_buffer" * api: add support of URL in hook_process/hook_process_hashtable (task #10247) * api: add new functions strcasecmp_range, strncasecmp_range, string_regex_flags, string_regcomp, hashtable_map_string, diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index cfb4fc994..979c1438a 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -8345,7 +8345,8 @@ Arguments: content of message received from IRC server (before charset decoding) | new content of message -| irc | irc_in2_xxx ^(1)^ | +| irc | irc_in2_xxx ^(1)^ + + (_new in version 0.3.5_) | server name | content of message received from IRC server (after charset decoding) | new content of message @@ -8360,25 +8361,32 @@ Arguments: empty string | "1" to display bar, "0" to hide it -| weechat | history_add | +| weechat | history_add + + (_new in version 0.3.2_) | string with buffer pointer ("0x123..") | - input buffer (from user) to add in command history (buffer and global) | + content of command line to add in command history (buffer and global) | string added to command history | weechat | input_text_content | string with buffer pointer ("0x123..") | - input buffer (from user) | - new content of input buffer + content of command line | + new content of command line | weechat | input_text_display | string with buffer pointer ("0x123..") | - input buffer (from user), without cursor tag | - new content of input buffer, for display only (input buffer is not changed) + content of command line, without cursor tag | + new string, for display only (command line is not changed) | weechat | input_text_display_with_cursor | string with buffer pointer ("0x123..") | - input buffer (from user), with cursor tag | - new content of input buffer, for display only (input buffer is not changed) + content of command line, with cursor tag | + new string, for display only (command line is not changed) + +| weechat | input_text_for_buffer + + (_new in version 0.3.7_) | + string with buffer pointer ("0x123..") | + content of command line sent to buffer (text or command) | + new content of command line sent to buffer | weechat | weechat_print | plugin;buffer_name;tags | diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 49b90fb2b..187f0fed5 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -8481,7 +8481,8 @@ Paramètres : contenu du message reçu du serveur IRC (avant décodage du jeu de caractères) | nouveau contenu du message -| irc | irc_in2_xxx ^(1)^ | +| irc | irc_in2_xxx ^(1)^ + + (_nouveau dans la version 0.3.5_) | nom de serveur | contenu du message reçu du serveur IRC (après décodage du jeu de caractères) | nouveau contenu du message @@ -8496,28 +8497,35 @@ Paramètres : chaîne vide | "1" pour afficher la barre, "0" pour la cacher -| weechat | history_add | +| weechat | history_add + + (_nouveau dans la version 0.3.2_) | chaîne avec un pointeur vers le tampon ("0x123..") | - chaîne saisie par l'utilisateur à ajouter à l'historique des commandes + contenu de la ligne de commande à ajouter à l'historique des commandes (tampon et global) | chaîne ajoutée à l'historique des commandes | weechat | input_text_content | chaîne avec un pointeur vers le tampon ("0x123..") | - chaîne saisie par l'utilisateur | - nouvelle chaîne + contenu de la ligne de commande | + nouvelle chaîne pour la ligne de commande | weechat | input_text_display | chaîne avec un pointeur vers le tampon ("0x123..") | - chaîne saisie par l'utilisateur, sans le code du curseur dedans | - nouvelle chaîne, pour affichage seulement (les données de l'utilisateur ne - sont pas changées) + contenu de la ligne de commande, sans le code du curseur dedans | + nouvelle chaîne, pour affichage seulement (la ligne de commande n'est pas + modifiée) | weechat | input_text_display_with_cursor | chaîne avec un pointeur vers le tampon ("0x123..") | - chaîne saisie par l'utilisateur, avec le code du curseur dedans | - nouvelle chaîne, pour affichage seulement (les données de l'utilisateur ne - sont pas changées) + contenu de la ligne de commande, avec le code du curseur dedans | + nouvelle chaîne, pour affichage seulement (la ligne de commande n'est pas + modifiée) + +| weechat | input_text_for_buffer + + (_nouveau dans la version 0.3.7_) | + chaîne avec un pointeur vers le tampon ("0x123..") | + contenu de la ligne de commande envoyée au tampon (texte ou commande) | + nouveau contenu de la ligne de commande envoyée au tampon | weechat | weechat_print | extension;nom_tampon;étiquettes | diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 1c01615b2..b1fe79834 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -8409,7 +8409,8 @@ Argomenti: contenuto del messaggio ricevuto dal server IRC (prima della codifica del set caratteri) | nuovo contenuto del messaggio -| irc | irc_in2_xxx ^(1)^ | +| irc | irc_in2_xxx ^(1)^ + + (_novità nella versione 0.3.5_) | nome server | contenuto del messaggio ricevuto dal server IRC (dopo la codifica del set caratteri) | nuovo contenuto del messaggio @@ -8424,27 +8425,37 @@ Argomenti: stringa vuota | "1" per visualizzare la barra, "0" per nasconderla -| weechat | history_add | +// TRANSLATION MISSING +| weechat | history_add + + (_novità nella versione 0.3.2_) | stringa con puntatore al buffer ("0x123..") | - input buffer (from user) to add in command history (buffer and global) | + content of command line to add in command history (buffer and global) | string added to command history +// TRANSLATION MISSING | weechat | input_text_content | stringa con puntatore al buffer ("0x123..") | - input buffer (dall'utente) | - nuovo contenuto del buffer di input + content of command line | + new content of command line +// TRANSLATION MISSING | weechat | input_text_display | stringa con puntatore al buffer ("0x123..") | - buffer di input (dall'utente), senza tag di cursore | - nuovo contenuto del buffer di input, solo per visualizzazione (il buffer - di input non è modificato) + content of command line, without cursor tag | + new string, for display only (command line is not changed) +// TRANSLATION MISSING | weechat | input_text_display_with_cursor | stringa con puntatore al buffer ("0x123..") | - buffer di input (dall'utente), con tag di cursore | - nuovo contenuto del buffer di input, solo per la visualizzazione (buffer di - input non è modificato) + content of command line, with cursor tag | + new string, for display only (command line is not changed) + +// TRANSLATION MISSING +| weechat | input_text_for_buffer + + (_novità nella versione 0.3.7_) | + stringa con puntatore al buffer ("0x123..") | + content of command line sent to buffer (text or command) | + new content of command line sent to buffer | weechat | weechat_print | plugin;buffer_name;tags | diff --git a/src/core/wee-input.c b/src/core/wee-input.c index 5d083bbaf..869568916 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -158,57 +158,71 @@ input_exec_command (struct t_gui_buffer *buffer, void input_data (struct t_gui_buffer *buffer, const char *data) { - char *pos, *buf; + char *pos, *buf, str_buffer[128], *new_data; const char *ptr_data, *ptr_data_for_buffer; int length, char_size; if (!buffer || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n')) return; - /* use new data (returned by plugin) */ - ptr_data = data; - while (ptr_data && ptr_data[0]) - { - pos = strchr (ptr_data, '\n'); - if (pos) - pos[0] = '\0'; + /* execute modifier "input_text_for_buffer" */ + snprintf (str_buffer, sizeof (str_buffer), + "0x%lx", (long unsigned int)buffer); + new_data = hook_modifier_exec (NULL, + "input_text_for_buffer", + str_buffer, + data); - ptr_data_for_buffer = string_input_for_buffer (ptr_data); - if (ptr_data_for_buffer) + /* data not dropped? */ + if (!new_data || new_data[0]) + { + ptr_data = (new_data) ? new_data : data; + while (ptr_data && ptr_data[0]) { - /* - * input string is NOT a command, send it to buffer input - * callback - */ - if (string_is_command_char (ptr_data_for_buffer)) + pos = strchr (ptr_data, '\n'); + if (pos) + pos[0] = '\0'; + + ptr_data_for_buffer = string_input_for_buffer (ptr_data); + if (ptr_data_for_buffer) { - char_size = utf8_char_size (ptr_data_for_buffer); - length = strlen (ptr_data_for_buffer) + char_size + 1; - buf = malloc (length); - if (buf) + /* + * input string is NOT a command, send it to buffer input + * callback + */ + if (string_is_command_char (ptr_data_for_buffer)) { - memcpy (buf, ptr_data_for_buffer, char_size); - snprintf (buf + char_size, length - char_size, - "%s", ptr_data_for_buffer); - input_exec_data (buffer, buf); - free (buf); + char_size = utf8_char_size (ptr_data_for_buffer); + length = strlen (ptr_data_for_buffer) + char_size + 1; + buf = malloc (length); + if (buf) + { + memcpy (buf, ptr_data_for_buffer, char_size); + snprintf (buf + char_size, length - char_size, + "%s", ptr_data_for_buffer); + input_exec_data (buffer, buf); + free (buf); + } } + else + input_exec_data (buffer, ptr_data_for_buffer); } else - input_exec_data (buffer, ptr_data_for_buffer); - } - else - { - /* input string is a command */ - input_exec_command (buffer, 1, buffer->plugin, ptr_data); - } + { + /* input string is a command */ + input_exec_command (buffer, 1, buffer->plugin, ptr_data); + } - if (pos) - { - pos[0] = '\n'; - ptr_data = pos + 1; + if (pos) + { + pos[0] = '\n'; + ptr_data = pos + 1; + } + else + ptr_data = NULL; } - else - ptr_data = NULL; } + + if (new_data) + free (new_data); }