Add new option weechat.look.command_chars, add functions string_is_command_char and string_input_for_buffer in plugin and script API

v2.8-utf8proc
Sebastien Helleu 2010-03-02 17:34:49 +01:00
parent 282f786c1a
commit 0543b0ccc7
35 changed files with 935 additions and 235 deletions

View File

@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
FlashCode <flashcode@flashtux.org>
v0.3.2-dev, 2010-02-27
v0.3.2-dev, 2010-03-02
Version 0.3.2 (under dev!)
@ -17,6 +17,8 @@ Version 0.3.2 (under dev!)
* core: add new option weechat.look.time_format to customize default format
for date/time displayed (localized date by default), add function
weechat_util_get_time_string in plugin API (patch #6914)
* core: add new option weechat.look.command_chars, add functions
string_is_command_char and string_input_for_buffer in plugin and script API
* core: use arguments for infolist "nicklist" to return only one nick or group
* gui: fix bug with global history, reset pointer to last entry after each user
input (bug #28754)

View File

@ -378,6 +378,11 @@
** type: boolean
** values: on, off (default value: off)
* *weechat.look.command_chars*
** description: chars used to determine if input string is a command or not: input must start with one of these chars; the slash ("/") is always considered as command prefix (example: ".$")
** type: string
** values: any string (default value: "")
* *weechat.look.day_change*
** description: display special message when day changes
** type: boolean

View File

@ -868,7 +868,7 @@ Return value:
* array of strings, NULL if problem (must be freed by calling
<<_weechat_string_free_split>> after use)
Examples:
C examples:
[source,C]
----------------------------------------
@ -1035,7 +1035,7 @@ Return value:
* formatted string (must be freed by calling "free" after use)
Examples:
C examples:
[source,C]
----------------------------------------
@ -1082,7 +1082,7 @@ Return value:
* string without color (must be freed by calling "free" after use)
Examples:
C examples:
[source,C]
----------------------------------------
@ -1127,7 +1127,7 @@ Arguments:
* 'to': pointer to string to store result (must be long enough, result is
longer than initial string)
Example:
C example:
[source,C]
----------------------------------------
@ -1158,7 +1158,7 @@ Return value:
* length of string stored in *to (does not count final '\0')
Example:
C example:
[source,C]
----------------------------------------
@ -1168,6 +1168,89 @@ length = weechat_string_decode_base64 (string, result);
/* length == 8, result == "abcdefgh" */
----------------------------------------
weechat_string_is_command_char
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Check if first char of string is a command char (default command char is '/').
Prototype:
[source,C]
----------------------------------------
int weechat_string_is_command_char (const char *string);
----------------------------------------
Arguments:
* 'string': string
Return value:
* 1 if first char of string is a command char, otherwise 0
C examples:
[source,C]
----------------------------------------
int command_char1 = weechat_string_is_command_char ("/test"); /* == 1 */
int command_char2 = weechat_string_is_command_char ("test"); /* == 0 */
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
weechat.string_is_command_char(string)
# examples
command_char1 = weechat.string_is_command_char("/test") # == 1
command_char2 = weechat.string_is_command_char("test") # == 0
----------------------------------------
weechat_string_input_for_buffer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Return pointer to input text for buffer (pointer inside "string" argument), or
NULL if it's a command.
Prototype:
[source,C]
----------------------------------------
const char *weechat_string_input_for_buffer (const char *string);
----------------------------------------
Arguments:
* 'string': string
Return value:
* pointer into "string", or NULL
C examples:
[source,C]
----------------------------------------
const char *str1 = weechat_string_input_for_buffer ("test"); /* "test" */
const char *str2 = weechat_string_input_for_buffer ("/test"); /* NULL */
const char *str3 = weechat_string_input_for_buffer ("//test"); /* "/test" */
----------------------------------------
Script (Python):
[source,python]
----------------------------------------
# prototype
str = weechat.string_input_for_buffer(string)
# examples
str1 = weechat.string_input_for_buffer("test") # "test"
str2 = weechat.string_input_for_buffer("/test") # ""
str3 = weechat.string_input_for_buffer("//test") # "/test"
----------------------------------------
[[utf-8]]
UTF-8
~~~~~

View File

@ -378,6 +378,11 @@
** type: booléen
** valeurs: on, off (valeur par défaut: off)
* *weechat.look.command_chars*
** description: caractères utilisés pour déterminer si la chaîne entrée est une commande ou non: l'entrée doit démarrer avec un de ces caractères; le slash ("/") est toujours considéré comme un préfixe de commande (exemple : ".$")
** type: chaîne
** valeurs: toute chaîne (valeur par défaut: "")
* *weechat.look.day_change*
** description: affiche un message quand le jour change
** type: booléen

File diff suppressed because it is too large Load Diff

View File

@ -378,6 +378,11 @@
** tipo: bool
** valori: on, off (valore predefinito: off)
* *weechat.look.command_chars*
** descrizione: chars used to determine if input string is a command or not: input must start with one of these chars; the slash ("/") is always considered as command prefix (example: ".$")
** tipo: stringa
** valori: qualsiasi stringa (valore predefinito: "")
* *weechat.look.day_change*
** descrizione: mostra un messaggio speciale al cambio di data
** tipo: bool

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1536,6 +1536,12 @@ msgstr ""
"byste toto nastavení zapnout, pro zobrazení skutečně bílé barvy místo "
"výchozí barvy popředí terminálu)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "zobrazit speiální zprávy při změně dne"

View File

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Nils G <weechatter@arcor.de>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1622,6 +1622,12 @@ msgstr ""
"Option zu aktivieren, andernfalls wird die voreingestellte Vordergrundfarbe "
"des Terminals genutzt)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "Spezielle Nachricht anzeigen, wenn ein neuer Tag beginnt"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1556,6 +1556,12 @@ msgstr ""
"activar esta opción para ver el blanco verdadero en vez del color de primer "
"plano del terminal por defecto)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "mostrar un mensaje especial cuando el día cambia"

View File

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"PO-Revision-Date: 2010-02-26 11:27+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-28 21:07+0100\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@ -1579,6 +1579,15 @@ msgstr ""
"devriez activer cette option pour voir du vrai blanc au lieu de la couleur "
"d'avant plan par défaut du terminal)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
"caractères utilisés pour déterminer si la chaîne entrée est une commande ou "
"non: l'entrée doit démarrer avec un de ces caractères; le slash (\"/\") est "
"toujours considéré comme un préfixe de commande (exemple : \".$\")"
msgid "display special message when day changes"
msgstr "affiche un message quand le jour change"

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1416,6 +1416,12 @@ msgstr ""
"hátteret, akkor bekapcsolhatja, hogy valódi fehéret kapjon a terminálban "
"használt betűszín helyett)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "speciális üzenet az aktuális nap megváltozásakor"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Weechat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Marco Paolone <marcopaolone@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1555,6 +1555,12 @@ msgstr ""
"per visualizzare il bianco reale invece del colore di primo piano "
"predefinito del terminale)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "mostra un messaggio speciale al cambio di data"

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Krzysztof Koroscik <soltys@szluug.org>\n"
"Language-Team: Polish\n"
@ -1582,6 +1582,12 @@ msgstr ""
"włączyć tą opcje, aby zobaczyć prawdziwy biały zamiast domyślnego koloru "
"czcionki w terminalu)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "wyświetlaj specjalną wiadomość, kiedy zmienia się dzień"

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: 2010-02-23 10:43+0100\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -1420,6 +1420,12 @@ msgstr ""
"белым фоном вам следует включить этот параметр чтобы видеть настоящий белый "
"цвет вместо цвета терминала по умолчанию)"
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr "отображать специальное сообщение при смене дня"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-02-26 11:22+0100\n"
"POT-Creation-Date: 2010-03-02 16:35+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1216,6 +1216,12 @@ msgid ""
"option to see real white instead of default term foreground color)"
msgstr ""
msgid ""
"chars used to determine if input string is a command or not: input must "
"start with one of these chars; the slash (\"/\") is always considered as "
"command prefix (example: \".$\")"
msgstr ""
msgid "display special message when day changes"
msgstr ""

View File

@ -932,7 +932,7 @@ command_command (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_ERROR;
}
}
if (argv_eol[2][0] == '/')
if (string_is_command_char (argv_eol[2]))
{
input_exec_command (buffer, 0, ptr_plugin, argv_eol[2]);
}
@ -2291,7 +2291,7 @@ command_mute (void *data, struct t_gui_buffer *buffer,
gui_chat_mute = mute_mode;
gui_chat_mute_buffer = mute_buffer;
if (ptr_command[0] == '/')
if (string_is_command_char (ptr_command))
{
input_exec_command (buffer, 1, NULL, ptr_command);
}

View File

@ -74,6 +74,7 @@ struct t_config_option *config_look_buffer_notify_default;
struct t_config_option *config_look_buffer_time_format;
struct t_config_option *config_look_color_nicks_number;
struct t_config_option *config_look_color_real_white;
struct t_config_option *config_look_command_chars;
struct t_config_option *config_look_day_change;
struct t_config_option *config_look_day_change_time_format;
struct t_config_option *config_look_highlight;
@ -1234,6 +1235,13 @@ config_weechat_init_options ()
"see real white instead of default term foreground "
"color)"),
NULL, 0, 0, "off", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL);
config_look_command_chars = config_file_new_option (
weechat_config_file, ptr_section,
"command_chars", "string",
N_("chars used to determine if input string is a command or not: "
"input must start with one of these chars; the slash (\"/\") is "
"always considered as command prefix (example: \".$\")"),
NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_day_change = config_file_new_option (
weechat_config_file, ptr_section,
"day_change", "boolean",

View File

@ -87,6 +87,7 @@ extern struct t_config_option *config_startup_weechat_slogan;
extern struct t_config_option *config_look_buffer_notify_default;
extern struct t_config_option *config_look_buffer_time_format;
extern struct t_config_option *config_look_command_chars;
extern struct t_config_option *config_look_color_nicks_number;
extern struct t_config_option *config_look_color_real_white;
extern struct t_config_option *config_look_day_change;

View File

@ -572,7 +572,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
{
struct t_hook *ptr_hook, *next_hook;
struct t_hook *hook_for_plugin, *hook_for_other_plugin;
char **argv, **argv_eol;
char **argv, **argv_eol, *ptr_command_name;
int argc, rc, number_for_other_plugin;
if (!buffer || !string || !string[0])
@ -592,6 +592,8 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
}
argv_eol = string_split (string, " ", 1, 0, NULL);
ptr_command_name = utf8_next_char (argv[0]);
hook_exec_start ();
hook_for_plugin = NULL;
@ -603,8 +605,8 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin,
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& ((argv[0][0] == '/') && (string_strcasecmp (argv[0] + 1,
HOOK_COMMAND(ptr_hook, command)) == 0)))
&& (string_strcasecmp (ptr_command_name,
HOOK_COMMAND(ptr_hook, command)) == 0))
{
if (ptr_hook->plugin == plugin)
{

View File

@ -31,31 +31,12 @@
#include "wee-config.h"
#include "wee-hook.h"
#include "wee-string.h"
#include "wee-utf8.h"
#include "../gui/gui-buffer.h"
#include "../gui/gui-chat.h"
#include "../plugins/plugin.h"
/*
* input_is_command: return 1 if line is a command, 0 otherwise
*/
int
input_is_command (const char *line)
{
char *pos_slash, *pos_space;
if (strncmp (line, "/*", 2) == 0)
return 0;
pos_slash = strchr (line + 1, '/');
pos_space = strchr (line + 1, ' ');
return (line[0] == '/')
&& (!pos_slash || (pos_space && pos_slash > pos_space));
}
/*
* input_exec_data: send data to buffer input callbackr
*/
@ -78,11 +59,9 @@ input_exec_data (struct t_gui_buffer *buffer, const char *data)
/*
* input_exec_command: execute a command (WeeChat internal or a plugin command)
* returns: 1 if command was executed succesfully
* 0 if error (command not executed)
*/
int
void
input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
@ -91,12 +70,12 @@ input_exec_command (struct t_gui_buffer *buffer,
int rc;
char *command, *pos, *ptr_args;
if ((!string) || (!string[0]) || (string[0] != '/'))
return 0;
if ((!string) || (!string[0]))
return;
command = strdup (string);
if (!command)
return 0;
return ;
/* look for end of command */
ptr_args = NULL;
@ -166,7 +145,6 @@ input_exec_command (struct t_gui_buffer *buffer,
break;
}
free (command);
return 0;
}
/*
@ -176,8 +154,9 @@ input_exec_command (struct t_gui_buffer *buffer,
void
input_data (struct t_gui_buffer *buffer, const char *data)
{
char *pos;
const char *ptr_data;
char *pos, *buf;
const char *ptr_data, *ptr_data_for_buffer;
int length, char_size;
if (!buffer || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n'))
return;
@ -190,14 +169,32 @@ input_data (struct t_gui_buffer *buffer, const char *data)
if (pos)
pos[0] = '\0';
if (input_is_command (ptr_data))
ptr_data_for_buffer = string_input_for_buffer (ptr_data);
if (ptr_data_for_buffer)
{
/* WeeChat or plugin command */
(void) input_exec_command (buffer, 1, buffer->plugin, ptr_data);
/* input string is NOT a command, send it to buffer input
callback */
if (string_is_command_char (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)
{
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);
/* input string is a command */
input_exec_command (buffer, 1, buffer->plugin, ptr_data);
}
if (pos)

View File

@ -23,10 +23,10 @@
struct t_gui_buffer;
struct t_weechat_plugin;
extern int input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
const char *string);
extern void input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
const char *string);
extern void input_data (struct t_gui_buffer *buffer, const char *data);
#endif /* wee-input.h */

View File

@ -50,6 +50,7 @@
#include "weechat.h"
#include "wee-string.h"
#include "wee-config.h"
#include "wee-utf8.h"
#include "../gui/gui-color.h"
@ -1410,3 +1411,79 @@ string_decode_base64 (const char *from, char *to)
return to_length;
}
/*
* string_is_command_char: return 1 if first char of string is a command char,
* otherwise 0
*/
int
string_is_command_char (const char *string)
{
const char *ptr_command_chars;
if (!string)
return 0;
if (string[0] == '/')
return 1;
ptr_command_chars = CONFIG_STRING(config_look_command_chars);
if (!ptr_command_chars || !ptr_command_chars[0])
return 0;
while (ptr_command_chars && ptr_command_chars[0])
{
if (utf8_charcmp (ptr_command_chars, string) == 0)
return 1;
ptr_command_chars = utf8_next_char (ptr_command_chars);
}
return 0;
}
/*
* string_input_for_buffer: return pointer to input text for buffer (pointer
* inside "string" argument)
* or return NULL if it's a command
* (by default, a command starts with a single '/')
*/
const char *
string_input_for_buffer (const char *string)
{
char *pos_slash, *pos_space, *next_char;
/* special case for C comments pasted in input line */
if (strncmp (string, "/*", 2) == 0)
return string;
/* special case if string starts with '/': to allow to paste a path line
"/path/to/file.txt", we check if next '/' is after a space or not */
if (string[0] == '/')
{
pos_slash = strchr (string + 1, '/');
pos_space = strchr (string + 1, ' ');
/* if there's no other '/' of if '/' is after first space,
then it is a command, and return NULL */
if (!pos_slash || (pos_space && pos_slash > pos_space))
return NULL;
return (string[1] == '/') ? string + 1 : string;
}
/* if string does not start with a command char, then it's not command */
if (!string_is_command_char (string))
return string;
/* check if first char is doubled: if yes, then it's not a command */
next_char = utf8_next_char (string);
if (!next_char || !next_char[0])
return string;
if (utf8_charcmp (string, next_char) == 0)
return next_char;
/* string is a command */
return NULL;
}

View File

@ -58,5 +58,7 @@ extern void string_iconv_fprintf (FILE *file, const char *data, ...);
extern char *string_format_size (unsigned long size);
extern void string_encode_base64 (const char *from, int length, char *to);
extern int string_decode_base64 (const char *from, char *to);
extern int string_is_command_char (const char *string);
extern const char *string_input_for_buffer (const char *string);
#endif /* wee-string.h */

View File

@ -1546,11 +1546,12 @@ gui_completion_find_context (struct t_gui_completion *completion,
const char *data, int size, int pos)
{
int i, command, command_arg, pos_start, pos_end;
char *prev_char;
/* look for context */
gui_completion_free_data (completion);
gui_completion_buffer_init (completion, completion->buffer);
command = (data[0] == '/') ? 1 : 0;
command = (string_input_for_buffer (data)) ? 0 : 1;
command_arg = 0;
i = 0;
while (i < pos)
@ -1623,8 +1624,8 @@ gui_completion_find_context (struct t_gui_completion *completion,
if (completion->context == GUI_COMPLETION_COMMAND)
{
pos_start++;
if (data[pos_start] == '/')
pos_start++;
if (string_is_command_char (data + pos_start))
pos_start += utf8_char_size (data + pos_start);
}
completion->base_word_pos = pos_start;
@ -1648,22 +1649,25 @@ gui_completion_find_context (struct t_gui_completion *completion,
if (completion->context == GUI_COMPLETION_COMMAND_ARG)
{
pos_start = 0;
while ((pos_start < size) && (data[pos_start] != '/'))
while ((pos_start < size) && !string_is_command_char (data + pos_start))
{
pos_start++;
pos_start += utf8_char_size (data + pos_start);
}
if (data[pos_start] == '/')
if (string_is_command_char (data + pos_start))
{
pos_start++;
if (data[pos_start] == '/')
pos_start++;
pos_start += utf8_char_size (data + pos_start);
if (string_is_command_char (data + pos_start))
pos_start += utf8_char_size (data + pos_start);
pos_end = pos_start;
while ((pos_end < size) && (data[pos_end] != ' '))
{
pos_end++;
pos_end += utf8_char_size (data + pos_end);
}
if (data[pos_end] == ' ')
pos_end--;
{
prev_char = utf8_prev_char (data, data + pos_end);
pos_end -= utf8_char_size (prev_char);
}
completion->base_command = malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)

View File

@ -371,10 +371,10 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
alias_command = malloc (1 + length1 + 1 + length2 + 1);
if (alias_command)
{
if (*ptr_cmd[0] != '/')
if (!weechat_string_is_command_char (*ptr_cmd))
strcpy (alias_command, "/");
else
strcpy (alias_command, "");
alias_command[0] = '\0';
strcat (alias_command, *ptr_cmd);
strcat (alias_command, " ");
@ -387,7 +387,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
}
else
{
if (*ptr_cmd[0] == '/')
if (weechat_string_is_command_char (*ptr_cmd))
{
alias_run_command (&buffer,
(args_replaced) ? args_replaced : *ptr_cmd);
@ -497,9 +497,9 @@ alias_new (const char *name, const char *command)
if (!name || !name[0] || !command || !command[0])
return NULL;
while (name[0] == '/')
while (weechat_string_is_command_char (name))
{
name++;
name = weechat_utf8_next_char (name);
}
ptr_alias = alias_search (name);
@ -514,7 +514,8 @@ alias_new (const char *name, const char *command)
if (str_completion)
{
snprintf (str_completion, length, "%%%%%s",
(command[0] == '/') ? command + 1 : command);
(weechat_string_is_command_char (command)) ?
weechat_utf8_next_char (command) : command);
}
new_hook = weechat_hook_command (name, command, NULL, NULL,
(str_completion) ? str_completion : NULL,
@ -587,8 +588,8 @@ alias_get_final_command (struct t_alias *alias)
return NULL;
}
ptr_alias = alias_search ((alias->command[0] == '/') ?
alias->command + 1 : alias->command);
ptr_alias = alias_search ((weechat_string_is_command_char (alias->command)) ?
weechat_utf8_next_char (alias->command) : alias->command);
if (ptr_alias)
{
alias->running = 1;
@ -596,8 +597,8 @@ alias_get_final_command (struct t_alias *alias)
alias->running = 0;
return result;
}
return (alias->command[0] == '/') ?
alias->command + 1 : alias->command;
return (weechat_string_is_command_char (alias->command)) ?
weechat_utf8_next_char (alias->command) : alias->command;
}
/*
@ -812,7 +813,8 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
if (argc > 1)
{
alias_name = (argv[1][0] == '/') ? argv[1] + 1 : argv[1];
alias_name = (weechat_string_is_command_char (argv[1])) ?
weechat_utf8_next_char (argv[1]) : argv[1];
if (argc > 2)
{
/* Define new alias */
@ -920,7 +922,8 @@ unalias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
{
for (i = 1; i < argc; i++)
{
alias_name = (argv[i][0] == '/') ? argv[i] + 1 : argv[i];
alias_name = (weechat_string_is_command_char (argv[i])) ?
weechat_utf8_next_char (argv[i]) : argv[i];
ptr_alias = alias_search (alias_name);
if (!ptr_alias)
{

View File

@ -733,10 +733,10 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
index_result = 0;
/* check if string is a command */
if ((ptr_string[0] == '/') && ptr_string[1] && (ptr_string[1] != '/')
&& (ptr_string[1] != ' '))
if (!weechat_string_input_for_buffer (ptr_string))
{
ptr_string++;
char_size = weechat_utf8_char_size (ptr_string);
ptr_string += char_size;
pos_space = ptr_string;
while (pos_space && pos_space[0] && (pos_space[0] != ' '))
{
@ -756,10 +756,11 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
free (result);
return NULL;
}
result[index_result++] = '/';
memcpy (result + index_result, aspell_last_modifier_string, char_size);
index_result += char_size;
strcpy (result + index_result, ptr_string);
index_result += strlen (ptr_string);
pos_space[0] = ' ';
ptr_string = pos_space;
}

View File

@ -121,7 +121,7 @@ irc_command_exec_all_channels (struct t_irc_server *server,
if (!command || !command[0])
return;
if (command[0] != '/')
if (!weechat_string_is_command_char (command))
{
length = 1 + strlen (command) + 1;
str_command = malloc (length);
@ -240,7 +240,7 @@ irc_command_exec_all_servers (const char *exclude_servers, const char *command)
if (!command || !command[0])
return;
if (command[0] != '/')
if (!weechat_string_is_command_char (command))
{
length = 1 + strlen (command) + 1;
str_command = malloc (length);

View File

@ -162,18 +162,19 @@ irc_input_data_cb (void *data, struct t_gui_buffer *buffer,
/* if send unknown commands is enabled and that input data is a command,
then send this command to IRC server */
if (weechat_config_boolean (irc_config_network_send_unknown_commands)
&& (input_data[0] == '/') && (input_data[1] != '/'))
&& !weechat_string_input_for_buffer (input_data))
{
if (ptr_server)
irc_server_sendf (ptr_server, IRC_SERVER_OUTQUEUE_PRIO_HIGH,
input_data + 1);
weechat_utf8_next_char (input_data));
return WEECHAT_RC_OK;
}
if (ptr_channel)
{
ptr_data = ((input_data[0] == '/') && (input_data[1] == '/')) ?
input_data + 1 : input_data;
ptr_data = weechat_string_input_for_buffer (input_data);
if (!ptr_data)
ptr_data = input_data;
data_with_colors = irc_color_encode (ptr_data,
weechat_config_boolean (irc_config_network_colors_send));

View File

@ -386,6 +386,8 @@ plugin_load (const char *filename)
new_plugin->string_remove_color = &gui_color_decode;
new_plugin->string_encode_base64 = &string_encode_base64;
new_plugin->string_decode_base64 = &string_decode_base64;
new_plugin->string_is_command_char = &string_is_command_char;
new_plugin->string_input_for_buffer = &string_input_for_buffer;
new_plugin->utf8_has_8bits = &utf8_has_8bits;
new_plugin->utf8_is_valid = &utf8_is_valid;

View File

@ -402,6 +402,81 @@ weechat_lua_api_string_remove_color (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_string_is_command_char: check if first char of string is a
* command char
*/
static int
weechat_lua_api_string_is_command_char (lua_State *L)
{
const char *string;
int n, value;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_is_command_char");
LUA_RETURN_INT(0);
}
string = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_is_command_char");
LUA_RETURN_INT(0);
}
string = lua_tostring (lua_current_interpreter, -1);
value = weechat_string_is_command_char (string);
LUA_RETURN_INT(value);
}
/*
* weechat_lua_api_string_input_for_buffer: return string with input text
* for buffer or empty string if
* it's a command
*/
static int
weechat_lua_api_string_input_for_buffer (lua_State *L)
{
const char *string, *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
LUA_RETURN_EMPTY;
}
string = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
LUA_RETURN_EMPTY;
}
string = lua_tostring (lua_current_interpreter, -1);
result = weechat_string_input_for_buffer (string);
LUA_RETURN_STRING(result);
}
/*
* weechat_lua_api_mkdir_home: create a directory in WeeChat home
*/
@ -7232,6 +7307,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "gettext", &weechat_lua_api_gettext },
{ "ngettext", &weechat_lua_api_ngettext },
{ "string_remove_color", &weechat_lua_api_string_remove_color },
{ "string_is_command_char", &weechat_lua_api_string_is_command_char },
{ "string_input_for_buffer", &weechat_lua_api_string_input_for_buffer },
{ "mkdir_home", &weechat_lua_api_mkdir_home },
{ "mkdir", &weechat_lua_api_mkdir },
{ "mkdir_parents", &weechat_lua_api_mkdir_parents },

View File

@ -345,6 +345,66 @@ XS (XS_weechat_api_string_remove_color)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::string_is_command_char: check if first char of string is a command
* char
*/
XS (XS_weechat_api_string_is_command_char)
{
int value;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_is_command_char");
PERL_RETURN_INT(0);
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_is_command_char");
PERL_RETURN_INT(0);
}
value = weechat_string_is_command_char (SvPV (ST (0), PL_na)); /* string */
PERL_RETURN_INT(value);
}
/*
* weechat::string_input_for_buffer: return string with input text for buffer
* or empty string if it's a command
*/
XS (XS_weechat_api_string_input_for_buffer)
{
const char *result;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
PERL_RETURN_EMPTY;
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
PERL_RETURN_EMPTY;
}
result = weechat_string_input_for_buffer (SvPV (ST (0), PL_na)); /* string */
PERL_RETURN_STRING(result);
}
/*
* weechat::mkdir_home: create a directory in WeeChat home
*/
@ -5790,6 +5850,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::gettext", XS_weechat_api_gettext, "weechat");
newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat");
newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat");
newXS ("weechat::string_is_command_char", XS_weechat_api_string_is_command_char, "weechat");
newXS ("weechat::string_input_for_buffer", XS_weechat_api_string_input_for_buffer, "weechat");
newXS ("weechat::mkdir_home", XS_weechat_api_mkdir_home, "weechat");
newXS ("weechat::mkdir", XS_weechat_api_mkdir, "weechat");
newXS ("weechat::mkdir_parents", XS_weechat_api_mkdir_parents, "weechat");

View File

@ -350,6 +350,73 @@ weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_string_is_command_char: check if first char of string is
* a command char
*/
static PyObject *
weechat_python_api_string_is_command_char (PyObject *self, PyObject *args)
{
char *string;
int value;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_is_command_char");
PYTHON_RETURN_INT(0);
}
string = NULL;
if (!PyArg_ParseTuple (args, "s", &string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_is_command_char");
PYTHON_RETURN_INT(0);
}
value = weechat_string_is_command_char (string);
PYTHON_RETURN_INT(value);
}
/*
* weechat_python_api_string_input_for_buffer: return string with input text
* for buffer or empty string if
* it's a command
*/
static PyObject *
weechat_python_api_string_input_for_buffer (PyObject *self, PyObject *args)
{
char *string;
const char *result;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
PYTHON_RETURN_EMPTY;
}
string = NULL;
if (!PyArg_ParseTuple (args, "s", &string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
PYTHON_RETURN_EMPTY;
}
result = weechat_string_input_for_buffer (string);
PYTHON_RETURN_STRING(result);
}
/*
* weechat_python_api_mkdir_home: create a directory in WeeChat home
*/
@ -6081,6 +6148,8 @@ PyMethodDef weechat_python_funcs[] =
{ "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
{ "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
{ "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
{ "string_is_command_char", &weechat_python_api_string_is_command_char, METH_VARARGS, "" },
{ "string_input_for_buffer", &weechat_python_api_string_input_for_buffer, METH_VARARGS, "" },
{ "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
{ "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
{ "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" },

View File

@ -407,6 +407,81 @@ weechat_ruby_api_string_remove_color (VALUE class, VALUE string,
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_string_is_command_char: check if first char of string is a
* command char
*/
static VALUE
weechat_ruby_api_string_is_command_char (VALUE class, VALUE string)
{
char *c_string;
int value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_is_command_char");
RUBY_RETURN_INT(0);
}
c_string = NULL;
if (NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_is_command_char");
RUBY_RETURN_INT(0);
}
Check_Type (string, T_STRING);
c_string = STR2CSTR (string);
value = weechat_string_is_command_char (c_string);
RUBY_RETURN_INT(value);
}
/*
* weechat_ruby_api_string_input_for_buffer: return string with input text
* for buffer or empty string if
* it's a command
*/
static VALUE
weechat_ruby_api_string_input_for_buffer (VALUE class, VALUE string)
{
char *c_string;
const char *result;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
RUBY_RETURN_EMPTY;
}
c_string = NULL;
if (NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
RUBY_RETURN_EMPTY;
}
Check_Type (string, T_STRING);
c_string = STR2CSTR (string);
result = weechat_string_input_for_buffer (c_string);
RUBY_RETURN_STRING(result);
}
/*
* weechat_ruby_api_mkdir_home: create a directory in WeeChat home
*/
@ -7023,6 +7098,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 2);
rb_define_module_function (ruby_mWeechat, "string_is_command_char", &weechat_ruby_api_string_is_command_char, 1);
rb_define_module_function (ruby_mWeechat, "string_input_for_buffer", &weechat_ruby_api_string_input_for_buffer, 1);
rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2);
rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2);
rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2);

View File

@ -446,7 +446,7 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
{
Tcl_Obj* objp;
char *result, *replacement, *string;
int i;
int i;
/* make C compiler happy */
(void) clientData;
@ -471,6 +471,72 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_string_is_command_char: check if first char of string is a
* command char
*/
static int
weechat_tcl_api_string_is_command_char (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
int result, i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_is_command_char");
TCL_RETURN_INT(0);
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_is_command_char");
TCL_RETURN_INT(0);
}
result = weechat_string_is_command_char (Tcl_GetStringFromObj (objv[1], &i)); /* string */
TCL_RETURN_INT(result);
}
/*
* weechat_tcl_api_string_input_for_buffer: return string with input text
* for buffer or empty string if
* it's a command
*/
static int
weechat_tcl_api_string_input_for_buffer (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
const char *result;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
TCL_RETURN_EMPTY;
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
TCL_RETURN_EMPTY;
}
result = weechat_string_input_for_buffer (Tcl_GetStringFromObj (objv[1], &i));
TCL_RETURN_STRING(result);
}
/*
* weechat_tcl_api_mkdir_home: create a directory in WeeChat home
*/
@ -6552,6 +6618,10 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
weechat_tcl_api_ngettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_remove_color",
weechat_tcl_api_string_remove_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_is_command_char",
weechat_tcl_api_string_is_command_char, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_input_for_buffer",
weechat_tcl_api_string_input_for_buffer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::mkdir_home",
weechat_tcl_api_mkdir_home, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::mkdir",

View File

@ -34,7 +34,7 @@ struct t_weelist;
struct timeval;
/* API version (used to check that plugin has same API and can be loaded) */
#define WEECHAT_PLUGIN_API_VERSION "20100216-01"
#define WEECHAT_PLUGIN_API_VERSION "20100302-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@ -172,6 +172,8 @@ struct t_weechat_plugin
char *(*string_remove_color) (const char *string, const char *replacement);
void (*string_encode_base64) (const char *from, int length, char *to);
int (*string_decode_base64) (const char *from, char *to);
int (*string_is_command_char) (const char *string);
const char *(*string_input_for_buffer) (const char *string);
/* UTF-8 strings */
int (*utf8_has_8bits) (const char *string);
@ -723,6 +725,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->string_encode_base64(__from, __length, __to)
#define weechat_string_decode_base64(__from, __to) \
weechat_plugin->string_decode_base64(__from, __to)
#define weechat_string_is_command_char(__string) \
weechat_plugin->string_is_command_char(__string)
#define weechat_string_input_for_buffer(__string) \
weechat_plugin->string_input_for_buffer(__string)
/* UTF-8 strings */
#define weechat_utf8_has_8bits(__string) \