diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-03-02 17:34:49 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-03-02 17:34:49 +0100 |
commit | 0543b0ccc7253bd38d5f473c3e1092e2b065b6ec (patch) | |
tree | 0ae2d27cddbf087212fdaf8853133c33999172b2 /src | |
parent | 282f786c1a75978ea0ad4399b7740abd6ff6486a (diff) | |
download | weechat-0543b0ccc7253bd38d5f473c3e1092e2b065b6ec.zip |
Add new option weechat.look.command_chars, add functions string_is_command_char and string_input_for_buffer in plugin and script API
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 4 | ||||
-rw-r--r-- | src/core/wee-config.c | 8 | ||||
-rw-r--r-- | src/core/wee-config.h | 1 | ||||
-rw-r--r-- | src/core/wee-hook.c | 8 | ||||
-rw-r--r-- | src/core/wee-input.c | 63 | ||||
-rw-r--r-- | src/core/wee-input.h | 8 | ||||
-rw-r--r-- | src/core/wee-string.c | 77 | ||||
-rw-r--r-- | src/core/wee-string.h | 2 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 26 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 27 | ||||
-rw-r--r-- | src/plugins/aspell/weechat-aspell.c | 11 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-input.c | 9 | ||||
-rw-r--r-- | src/plugins/plugin.c | 2 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 77 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 62 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 69 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 77 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 72 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 8 |
20 files changed, 537 insertions, 78 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 23c800012..a4b28b31d 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -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); } diff --git a/src/core/wee-config.c b/src/core/wee-config.c index fa8f4a5b7..3a96c5f23 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -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", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index b9337f051..0c3e4fb5a 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -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; diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index fc298e226..8286e72b1 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -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) { diff --git a/src/core/wee-input.c b/src/core/wee-input.c index 2622192c0..c47ce6b7f 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -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) diff --git a/src/core/wee-input.h b/src/core/wee-input.h index b16af25d0..a4000eadb 100644 --- a/src/core/wee-input.h +++ b/src/core/wee-input.h @@ -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 */ diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 94c626f9d..a0ee93505 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -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; +} diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 2666b79c2..477d86e4c 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -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 */ diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 698bddabb..f509c5481 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -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++) diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 7821b7c8f..d93a51b66 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -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) { diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 9ff334cde..dcb8f0547 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -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; } diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 5f907ced2..9500f7beb 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -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); diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index ba3ce319e..caa1767dd 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -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)); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 38e72c022..91c12e8e3 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -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; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 7554070b8..aa52fb6c0 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -403,6 +403,81 @@ weechat_lua_api_string_remove_color (lua_State *L) } /* + * 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 }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 660af505f..08b84d8e7 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -346,6 +346,66 @@ XS (XS_weechat_api_string_remove_color) } /* + * 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"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 5ab77a57a..f4205b59e 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -351,6 +351,73 @@ weechat_python_api_string_remove_color (PyObject *self, PyObject *args) } /* + * 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, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index a5af066cd..af98c38d5 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -408,6 +408,81 @@ weechat_ruby_api_string_remove_color (VALUE class, VALUE string, } /* + * 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); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 65fcb1bd4..84f75aa7d 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -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; @@ -472,6 +472,72 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp, } /* + * 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", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index f364ecc26..3e68a6dff 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -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) \ |