diff options
Diffstat (limited to 'src/plugins/scripts')
44 files changed, 0 insertions, 47699 deletions
diff --git a/src/plugins/scripts/CMakeLists.txt b/src/plugins/scripts/CMakeLists.txt deleted file mode 100644 index cd97d6bb1..000000000 --- a/src/plugins/scripts/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -SET(LIB_SCRIPTS_SRC script.c script.h script-callback.c script-callback.h -script-api.c script-api.h) - -ADD_DEFINITIONS(${CMAKE_SHARED_LIBRARY_C_FLAGS}) -INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) -ADD_LIBRARY(weechat_scripts STATIC ${LIB_SCRIPTS_SRC}) - -IF(ENABLE_PERL) - FIND_PACKAGE(Perl) - IF(PERL_FOUND) - ADD_SUBDIRECTORY( perl ) - ENDIF(PERL_FOUND) -ENDIF(ENABLE_PERL) - -IF(ENABLE_PYTHON) - FIND_PACKAGE(Python) - IF(PYTHON_FOUND) - ADD_SUBDIRECTORY( python ) - ENDIF(PYTHON_FOUND) -ENDIF(ENABLE_PYTHON) - -IF(ENABLE_RUBY) - FIND_PACKAGE(Ruby) - IF(RUBY_FOUND) - ADD_SUBDIRECTORY( ruby ) - ENDIF(RUBY_FOUND) -ENDIF(ENABLE_RUBY) - -IF(ENABLE_LUA) - FIND_PACKAGE(Lua) - IF(LUA_FOUND) - ADD_SUBDIRECTORY( lua ) - ENDIF(LUA_FOUND) -ENDIF(ENABLE_LUA) - -IF(ENABLE_TCL) - FIND_PACKAGE(TCL) - IF(TCL_FOUND) - ADD_SUBDIRECTORY( tcl ) - ENDIF(TCL_FOUND) -ENDIF(ENABLE_TCL) - -IF(ENABLE_GUILE) - FIND_PACKAGE(Guile) - IF(GUILE_FOUND) - ADD_SUBDIRECTORY( guile ) - ENDIF(GUILE_FOUND) -ENDIF(ENABLE_GUILE) diff --git a/src/plugins/scripts/Makefile.am b/src/plugins/scripts/Makefile.am deleted file mode 100644 index a30bbf8ce..000000000 --- a/src/plugins/scripts/Makefile.am +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" - -noinst_LTLIBRARIES = lib_weechat_plugins_scripts.la - -lib_weechat_plugins_scripts_la_SOURCES = script.c \ - script.h \ - script-callback.c \ - script-callback.h \ - script-api.c \ - script-api.h - -if PLUGIN_PERL -perl_dir = perl -endif - -if PLUGIN_PYTHON -python_dir = python -endif - -if PLUGIN_RUBY -ruby_dir = ruby -endif - -if PLUGIN_LUA -lua_dir = lua -endif - -if PLUGIN_TCL -tcl_dir = tcl -endif - -if PLUGIN_GUILE -guile_dir = guile -endif - -SUBDIRS = . $(perl_dir) $(python_dir) $(ruby_dir) $(lua_dir) $(tcl_dir) $(guile_dir) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/guile/CMakeLists.txt b/src/plugins/scripts/guile/CMakeLists.txt deleted file mode 100644 index 2092f4e49..000000000 --- a/src/plugins/scripts/guile/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(guile MODULE weechat-guile.c weechat-guile.h -weechat-guile-api.c weechat-guile-api.h) - -SET_TARGET_PROPERTIES(guile PROPERTIES PREFIX "") - -IF(GUILE_FOUND) - INCLUDE_DIRECTORIES(${GUILE_INCLUDE_DIRS}) - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${GUILE_LFLAGS}") - TARGET_LINK_LIBRARIES(guile ${GUILE_LIBRARY} weechat_scripts) -ENDIF(GUILE_FOUND) - -INSTALL(TARGETS guile LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/guile/Makefile.am b/src/plugins/scripts/guile/Makefile.am deleted file mode 100644 index 47571527d..000000000 --- a/src/plugins/scripts/guile/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GUILE_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = guile.la - -guile_la_SOURCES = weechat-guile.c \ - weechat-guile.h \ - weechat-guile-api.c \ - weechat-guile-api.h -guile_la_LDFLAGS = -module -guile_la_LIBADD = ../lib_weechat_plugins_scripts.la $(GUILE_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/guile/weechat-guile-api.c b/src/plugins/scripts/guile/weechat-guile-api.c deleted file mode 100644 index f2523ea4e..000000000 --- a/src/plugins/scripts/guile/weechat-guile-api.c +++ /dev/null @@ -1,5587 +0,0 @@ -/* - * Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-guile-api.c: guile API functions - */ - -#undef _ - -#include <libguile.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-guile.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *guile_function_name = __name; \ - if (__init \ - && (!guile_current_script || !guile_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(GUILE_CURRENT_SCRIPT_NAME, \ - guile_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(GUILE_CURRENT_SCRIPT_NAME, \ - guile_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_guile_plugin, GUILE_CURRENT_SCRIPT_NAME, \ - guile_function_name, __string) -#define API_RETURN_OK return SCM_BOOL_T; -#define API_RETURN_ERROR return SCM_BOOL_F; -#define API_RETURN_EMPTY \ - return scm_from_locale_string(""); -#define API_RETURN_STRING(__string) \ - if (__string) \ - return scm_from_locale_string(__string); \ - return scm_from_locale_string("") -#define API_RETURN_STRING_FREE(__string) \ - if (__string) \ - { \ - return_value = scm_from_locale_string (__string); \ - free (__string); \ - return return_value; \ - } \ - return scm_from_locale_string("") -#define API_RETURN_INT(__int) \ - return scm_from_int (__int); -#define API_RETURN_LONG(__long) \ - return scm_from_long (__long); - -#define API_DEF_FUNC(__name, __argc) \ - scm_c_define_gsubr ("weechat:" #__name, __argc, 0, 0, \ - &weechat_guile_api_##__name); \ - scm_c_export ("weechat:" #__name, NULL); - - -/* - * weechat_guile_api_register: startup function for all WeeChat Guile scripts - */ - -SCM -weechat_guile_api_register (SCM name, SCM author, SCM version, SCM license, - SCM description, SCM shutdown_func, SCM charset) -{ - API_FUNC(0, "register", API_RETURN_ERROR); - if (guile_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, - guile_registered_script->name); - API_RETURN_ERROR; - } - guile_current_script = NULL; - guile_registered_script = NULL; - if (!scm_is_string (name) || !scm_is_string (author) - || !scm_is_string (version) || !scm_is_string (license) - || !scm_is_string (description) || !scm_is_string (shutdown_func) - || !scm_is_string (charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (script_search (weechat_guile_plugin, guile_scripts, - scm_i_string_chars (name))) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, name); - API_RETURN_ERROR; - } - - /* register script */ - guile_current_script = script_add (weechat_guile_plugin, - &guile_scripts, &last_guile_script, - (guile_current_script_filename) ? - guile_current_script_filename : "", - scm_i_string_chars (name), - scm_i_string_chars (author), - scm_i_string_chars (version), - scm_i_string_chars (license), - scm_i_string_chars (description), - scm_i_string_chars (shutdown_func), - scm_i_string_chars (charset)); - if (guile_current_script) - { - guile_registered_script = guile_current_script; - if ((weechat_guile_plugin->debug >= 2) || !guile_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - GUILE_PLUGIN_NAME, - scm_i_string_chars (name), - scm_i_string_chars (version), - scm_i_string_chars (description)); - } - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat_guile_api_plugin_get_name: get name of plugin (return "core" for - * WeeChat core) - */ - -SCM -weechat_guile_api_plugin_get_name (SCM plugin) -{ - const char *result; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - if (!scm_is_string (plugin)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_plugin_get_name (API_STR2PTR(scm_i_string_chars (plugin))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_charset_set: set script charset - */ - -SCM -weechat_guile_api_charset_set (SCM charset) -{ - API_FUNC(1, "charset_set", API_RETURN_ERROR); - if (!scm_is_string (charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_charset_set (guile_current_script, scm_i_string_chars (charset)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_iconv_to_internal: convert string to internal WeeChat charset - */ - -SCM -weechat_guile_api_iconv_to_internal (SCM charset, SCM string) -{ - char *result; - SCM return_value; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - if (!scm_is_string (charset) || !scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_iconv_to_internal (scm_i_string_chars (charset), - scm_i_string_chars (string)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_iconv_from_internal: convert string from WeeChat internal - * charset to another one - */ - -SCM -weechat_guile_api_iconv_from_internal (SCM charset, SCM string) -{ - char *result; - SCM return_value; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - if (!scm_is_string (charset) || !scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_iconv_from_internal (scm_i_string_chars (charset), - scm_i_string_chars (string)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_gettext: get translated string - */ - -SCM -weechat_guile_api_gettext (SCM string) -{ - const char *result; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - if (!scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_gettext (scm_i_string_chars (string)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_ngettext: get translated string with plural form - */ - -SCM -weechat_guile_api_ngettext (SCM single, SCM plural, SCM count) -{ - const char *result; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - if (!scm_is_string (single) || !scm_is_string (plural) - || !scm_is_integer (count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_ngettext (scm_i_string_chars (single), - scm_i_string_chars (plural), - scm_to_int (count)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other "*" - * are allowed inside mask - */ - -SCM -weechat_guile_api_string_match (SCM string, SCM mask, SCM case_sensitive) -{ - int value; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - if (!scm_is_string (string) || !scm_is_string (mask) - || !scm_is_integer (case_sensitive)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_match (scm_i_string_chars (string), - scm_i_string_chars (mask), - scm_to_int (case_sensitive)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_string_has_highlight: return 1 if string contains a - * highlight (using list of words to - * highlight) - * return 0 if no highlight is found in - * string - */ - -SCM -weechat_guile_api_string_has_highlight (SCM string, SCM highlight_words) -{ - int value; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - if (!scm_is_string (string) || !scm_is_string (highlight_words)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight (scm_i_string_chars (string), - scm_i_string_chars (highlight_words)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_string_has_highlight_regex: return 1 if string contains a - * highlight (using regular - * expression) - * return 0 if no highlight is - * found in string - */ - -SCM -weechat_guile_api_string_has_highlight_regex (SCM string, SCM regex) -{ - int value; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - if (!scm_is_string (string) || !scm_is_string (regex)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight_regex (scm_i_string_chars (string), - scm_i_string_chars (regex)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_string_mask_to_regex: convert a mask (string with only - * "*" as wildcard) to a regex, paying - * attention to special chars in a - * regex - */ - -SCM -weechat_guile_api_string_mask_to_regex (SCM mask) -{ - char *result; - SCM return_value; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - if (!scm_is_string (mask)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_mask_to_regex (scm_i_string_chars (mask)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_string_remove_color: remove WeeChat color codes from string - */ - -SCM -weechat_guile_api_string_remove_color (SCM string, SCM replacement) -{ - char *result; - SCM return_value; - - API_FUNC(1, "string_remove_color", API_RETURN_EMPTY); - if (!scm_is_string (string) || !scm_is_string (replacement)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_remove_color (scm_i_string_chars (string), - scm_i_string_chars (replacement)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_string_is_command_char: check if first char of string is a - * command char - */ - -SCM -weechat_guile_api_string_is_command_char (SCM string) -{ - int value; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - if (!scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_is_command_char (scm_i_string_chars (string)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_string_input_for_buffer: return string with input text - * for buffer or empty string if - * it's a command - */ - -SCM -weechat_guile_api_string_input_for_buffer (SCM string) -{ - const char *result; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - if (!scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_input_for_buffer (scm_i_string_chars (string)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_mkdir_home: create a directory in WeeChat home - */ - -SCM -weechat_guile_api_mkdir_home (SCM directory, SCM mode) -{ - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - if (!scm_is_string (directory) || !scm_is_integer (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_home (scm_i_string_chars (directory), scm_to_int (mode))) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_guile_api_mkdir: create a directory - */ - -SCM -weechat_guile_api_mkdir (SCM directory, SCM mode) -{ - API_FUNC(1, "mkdir", API_RETURN_ERROR); - if (!scm_is_string (directory) || !scm_is_integer (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir (scm_i_string_chars (directory), scm_to_int (mode))) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_guile_api_mkdir_parents: create a directory and make parent - * directories as needed - */ - -SCM -weechat_guile_api_mkdir_parents (SCM directory, SCM mode) -{ - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - if (!scm_is_string (directory) || !scm_is_integer (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_parents (scm_i_string_chars (directory), scm_to_int (mode))) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_guile_api_list_new: create a new list - */ - -SCM -weechat_guile_api_list_new () -{ - char *result; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_add: add a string to list - */ - -SCM -weechat_guile_api_list_add (SCM weelist, SCM data, SCM where, SCM user_data) -{ - char *result; - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - if (!scm_is_string (weelist) || !scm_is_string (data) - || !scm_is_string (where) || !scm_is_string (user_data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(scm_i_string_chars (weelist)), - scm_i_string_chars (data), - scm_i_string_chars (where), - API_STR2PTR(scm_i_string_chars (user_data)))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_search: search a string in list - */ - -SCM -weechat_guile_api_list_search (SCM weelist, SCM data) -{ - char *result; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - if (!scm_is_string (weelist) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(scm_i_string_chars (weelist)), - scm_i_string_chars (data))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_search_pos: search position of a string in list - */ - -SCM -weechat_guile_api_list_search_pos (SCM weelist, SCM data) -{ - int pos; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - if (!scm_is_string (weelist) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - pos = weechat_list_search_pos (API_STR2PTR(scm_i_string_chars (weelist)), - scm_i_string_chars (data)); - - API_RETURN_INT(pos); -} - -/* - * weechat_guile_api_list_casesearch: search a string in list (ignore case) - */ - -SCM -weechat_guile_api_list_casesearch (SCM weelist, SCM data) -{ - char *result; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - if (!scm_is_string (weelist) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(scm_i_string_chars (weelist)), - scm_i_string_chars (data))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -SCM -weechat_guile_api_list_casesearch_pos (SCM weelist, SCM data) -{ - int pos; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - if (!scm_is_string (weelist) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - pos = weechat_list_casesearch_pos (API_STR2PTR(scm_i_string_chars (weelist)), - scm_i_string_chars (data)); - - API_RETURN_INT(pos); -} - -/* - * weechat_guile_api_list_get: get item by position - */ - -SCM -weechat_guile_api_list_get (SCM weelist, SCM position) -{ - char *result; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - if (!scm_is_string (weelist) || !scm_is_integer (position)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(scm_i_string_chars (weelist)), - scm_to_int (position))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_set: set new value for item - */ - -SCM -weechat_guile_api_list_set (SCM item, SCM new_value) -{ - API_FUNC(1, "list_set", API_RETURN_ERROR); - if (!scm_is_string (item) || !scm_is_string (new_value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_set (API_STR2PTR(scm_i_string_chars (item)), - scm_i_string_chars (new_value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_list_next: get next item - */ - -SCM -weechat_guile_api_list_next (SCM item) -{ - char *result; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - if (!scm_is_string (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(scm_i_string_chars (item)))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_prev: get previous item - */ - -SCM -weechat_guile_api_list_prev (SCM item) -{ - char *result; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - if (!scm_is_string (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(scm_i_string_chars (item)))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_string: get string value of item - */ - -SCM -weechat_guile_api_list_string (SCM item) -{ - const char *result; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - if (!scm_is_string (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_list_string (API_STR2PTR(scm_i_string_chars (item))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_list_size: get number of elements in list - */ - -SCM -weechat_guile_api_list_size (SCM weelist) -{ - int size; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - if (!scm_is_string (weelist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - size = weechat_list_size (API_STR2PTR(scm_i_string_chars (weelist))); - - API_RETURN_INT(size); -} - -/* - * weechat_guile_api_list_remove: remove item from list - */ - -SCM -weechat_guile_api_list_remove (SCM weelist, SCM item) -{ - API_FUNC(1, "list_remove", API_RETURN_ERROR); - if (!scm_is_string (weelist) || !scm_is_string (item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove (API_STR2PTR(scm_i_string_chars (weelist)), - API_STR2PTR(scm_i_string_chars (item))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_list_remove_all: remove all items from list - */ - -SCM -weechat_guile_api_list_remove_all (SCM weelist) -{ - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - if (!scm_is_string (weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove_all (API_STR2PTR(scm_i_string_chars (weelist))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_list_free: free list - */ - -SCM -weechat_guile_api_list_free (SCM weelist) -{ - API_FUNC(1, "list_free", API_RETURN_ERROR); - if (!scm_is_string (weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_free (API_STR2PTR(scm_i_string_chars (weelist))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_reload_cb: callback for config reload - */ - -int -weechat_guile_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat_guile_api_config_new: create a new configuration file - */ - -SCM -weechat_guile_api_config_new (SCM name, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - if (!scm_is_string (name) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (name), - &weechat_guile_api_config_reload_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_read_cb: callback for reading option in section - */ - -int -weechat_guile_api_config_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_guile_api_config_section_write_cb: callback for writing section - */ - -int -weechat_guile_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_guile_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_guile_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_guile_api_config_section_create_option_cb: callback to create an - * option - */ - -int -weechat_guile_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_guile_api_config_section_delete_option_cb: callback to delete an - * option - */ - -int -weechat_guile_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat_guile_api_config_new_section: create a new section in configuration file - */ - -SCM -weechat_guile_api_config_new_section (SCM args) -{ - SCM config_file, name, user_can_add_options, user_can_delete_options; - SCM function_read, data_read, function_write, data_write; - SCM function_write_default, data_write_default, function_create_option; - SCM data_create_option, function_delete_option, data_delete_option; - char *result; - SCM return_value; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - if (!scm_list_p (args) || (scm_to_int (scm_length (args)) != 14)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = scm_list_ref (args, scm_from_int (0)); - name = scm_list_ref (args, scm_from_int (1)); - user_can_add_options = scm_list_ref (args, scm_from_int (2)); - user_can_delete_options = scm_list_ref (args, scm_from_int (3)); - function_read = scm_list_ref (args, scm_from_int (4)); - data_read = scm_list_ref (args, scm_from_int (5)); - function_write = scm_list_ref (args, scm_from_int (6)); - data_write = scm_list_ref (args, scm_from_int (7)); - function_write_default = scm_list_ref (args, scm_from_int (8)); - data_write_default = scm_list_ref (args, scm_from_int (9)); - function_create_option = scm_list_ref (args, scm_from_int (10)); - data_create_option = scm_list_ref (args, scm_from_int (11)); - function_delete_option = scm_list_ref (args, scm_from_int (12)); - data_delete_option = scm_list_ref (args, scm_from_int (13)); - - if (!scm_is_string (config_file) || !scm_is_string (name) - || !scm_is_integer (user_can_add_options) || !scm_is_integer (user_can_delete_options) - || !scm_is_string (function_read) || !scm_is_string (data_read) - || !scm_is_string (function_write) || !scm_is_string (data_write) - || !scm_is_string (function_write_default) || !scm_is_string (data_write_default) - || !scm_is_string (function_create_option) || !scm_is_string (data_create_option) - || !scm_is_string (function_delete_option) || !scm_is_string (data_delete_option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new_section (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (config_file)), - scm_i_string_chars (name), - scm_to_int (user_can_add_options), - scm_to_int (user_can_delete_options), - &weechat_guile_api_config_read_cb, - scm_i_string_chars (function_read), - scm_i_string_chars (data_read), - &weechat_guile_api_config_section_write_cb, - scm_i_string_chars (function_write), - scm_i_string_chars (data_write), - &weechat_guile_api_config_section_write_default_cb, - scm_i_string_chars (function_write_default), - scm_i_string_chars (data_write_default), - &weechat_guile_api_config_section_create_option_cb, - scm_i_string_chars (function_create_option), - scm_i_string_chars (data_create_option), - &weechat_guile_api_config_section_delete_option_cb, - scm_i_string_chars (function_delete_option), - scm_i_string_chars (data_delete_option))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_search_section: search section in configuration file - */ - -SCM -weechat_guile_api_config_search_section (SCM config_file, SCM section_name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - if (!scm_is_string (config_file) || !scm_is_string (section_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(scm_i_string_chars (config_file)), - scm_i_string_chars (section_name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_option_check_value_cb: callback for checking new - * value for option - */ - -int -weechat_guile_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_guile_api_config_option_change_cb: callback for option changed - */ - -void -weechat_guile_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_guile_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_guile_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_guile_api_config_new_option: create a new option in section - */ - -SCM -weechat_guile_api_config_new_option (SCM args) -{ - SCM config_file, section, name, type, description, string_values, min; - SCM max, default_value, value, null_value_allowed, function_check_value; - SCM data_check_value, function_change, data_change, function_delete; - SCM data_delete; - char *result; - SCM return_value; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - if (!scm_list_p (args) || (scm_to_int (scm_length (args)) != 17)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = scm_list_ref (args, scm_from_int (0)); - section = scm_list_ref (args, scm_from_int (1)); - name = scm_list_ref (args, scm_from_int (2)); - type = scm_list_ref (args, scm_from_int (3)); - description = scm_list_ref (args, scm_from_int (4)); - string_values = scm_list_ref (args, scm_from_int (5)); - min = scm_list_ref (args, scm_from_int (6)); - max = scm_list_ref (args, scm_from_int (7)); - default_value = scm_list_ref (args, scm_from_int (8)); - value = scm_list_ref (args, scm_from_int (9)); - null_value_allowed = scm_list_ref (args, scm_from_int (10)); - function_check_value = scm_list_ref (args, scm_from_int (11)); - data_check_value = scm_list_ref (args, scm_from_int (12)); - function_change = scm_list_ref (args, scm_from_int (13)); - data_change = scm_list_ref (args, scm_from_int (14)); - function_delete = scm_list_ref (args, scm_from_int (15)); - data_delete = scm_list_ref (args, scm_from_int (16)); - - if (!scm_is_string (config_file) || !scm_is_string (section) - || !scm_is_string (name) || !scm_is_string (type) - || !scm_is_string (description) || !scm_is_string (string_values) - || !scm_is_integer (min) || !scm_is_integer (max) - || !scm_is_string (default_value) || !scm_is_string (value) - || !scm_is_integer (null_value_allowed) - || !scm_is_string (function_check_value) - || !scm_is_string (data_check_value) - || !scm_is_string (function_change) || !scm_is_string (data_change) - || !scm_is_string (function_delete) || !scm_is_string (data_delete)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new_option (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (config_file)), - API_STR2PTR(scm_i_string_chars (section)), - scm_i_string_chars (name), - scm_i_string_chars (type), - scm_i_string_chars (description), - scm_i_string_chars (string_values), - scm_to_int (min), - scm_to_int (max), - scm_i_string_chars (default_value), - scm_i_string_chars (value), - scm_to_int (null_value_allowed), - &weechat_guile_api_config_option_check_value_cb, - scm_i_string_chars (function_check_value), - scm_i_string_chars (data_check_value), - &weechat_guile_api_config_option_change_cb, - scm_i_string_chars (function_change), - scm_i_string_chars (data_change), - &weechat_guile_api_config_option_delete_cb, - scm_i_string_chars (function_delete), - scm_i_string_chars (data_delete))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_search_option: search option in configuration file - * or section - */ - -SCM -weechat_guile_api_config_search_option (SCM config_file, SCM section, - SCM option_name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - if (!scm_is_string (config_file) || !scm_is_string (section) - || !scm_is_string (option_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(scm_i_string_chars (config_file)), - API_STR2PTR(scm_i_string_chars (section)), - scm_i_string_chars (option_name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_string_to_boolean: return boolean value of a string - */ - -SCM -weechat_guile_api_config_string_to_boolean (SCM text) -{ - int value; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - if (!scm_is_string (text)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_string_to_boolean (scm_i_string_chars (text)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_option_reset: reset option with default value - */ - -SCM -weechat_guile_api_config_option_reset (SCM option, SCM run_callback) -{ - int rc; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - if (!scm_is_string (option) || !scm_is_integer (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = weechat_config_option_reset (API_STR2PTR(scm_i_string_chars (option)), - scm_to_int (run_callback)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_option_set: set new value for option - */ - -SCM -weechat_guile_api_config_option_set (SCM option, SCM new_value, - SCM run_callback) -{ - int rc; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (!scm_is_string (option) || !scm_is_string (new_value) - || !scm_is_integer (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = weechat_config_option_set (API_STR2PTR(scm_i_string_chars (option)), - scm_i_string_chars (new_value), - scm_to_int (run_callback)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_option_set_null: set null (undefined) value for - * option - */ - -SCM -weechat_guile_api_config_option_set_null (SCM option, SCM run_callback) -{ - int rc; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (!scm_is_string (option) || !scm_is_integer (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = weechat_config_option_set_null (API_STR2PTR(scm_i_string_chars (option)), - scm_to_int (run_callback)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_option_unset: unset an option - */ - -SCM -weechat_guile_api_config_option_unset (SCM option) -{ - int rc; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - rc = weechat_config_option_unset (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_option_rename: rename an option - */ - -SCM -weechat_guile_api_config_option_rename (SCM option, SCM new_name) -{ - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - if (!scm_is_string (option) || !scm_is_string (new_name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_option_rename (API_STR2PTR(scm_i_string_chars (option)), - scm_i_string_chars (new_name)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_option_is_null: return 1 if value of option is null - */ - -SCM -weechat_guile_api_config_option_is_null (SCM option) -{ - int value; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_is_null (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_option_default_is_null: return 1 if value of option - * is null - */ - -SCM -weechat_guile_api_config_option_default_is_null (SCM option) -{ - int value; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_default_is_null (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_boolean: return boolean value of option - */ - -SCM -weechat_guile_api_config_boolean (SCM option) -{ - int value; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_boolean_default: return default boolean value of option - */ - -SCM -weechat_guile_api_config_boolean_default (SCM option) -{ - int value; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean_default (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_integer: return integer value of option - */ - -SCM -weechat_guile_api_config_integer (SCM option) -{ - int value; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_integer_default: return default integer value of option - */ - -SCM -weechat_guile_api_config_integer_default (SCM option) -{ - int value; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer_default (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_config_string: return string value of option - */ - -SCM -weechat_guile_api_config_string (SCM option) -{ - const char *result; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_config_string_default: return default string value of option - */ - -SCM -weechat_guile_api_config_string_default (SCM option) -{ - const char *result; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string_default (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_config_color: return color value of option - */ - -SCM -weechat_guile_api_config_color (SCM option) -{ - const char *result; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_config_color_default: return default color value of option - */ - -SCM -weechat_guile_api_config_color_default (SCM option) -{ - const char *result; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color_default (API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_config_write_option: write an option in configuration file - */ - -SCM -weechat_guile_api_config_write_option (SCM config_file, SCM option) -{ - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - if (!scm_is_string (config_file) || !scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_write_option (API_STR2PTR(scm_i_string_chars (config_file)), - API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_write_line: write a line in configuration file - */ - -SCM -weechat_guile_api_config_write_line (SCM config_file, - SCM option_name, SCM value) -{ - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - if (!scm_is_string (config_file) || !scm_is_string (option_name) || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_write_line (API_STR2PTR(scm_i_string_chars (config_file)), - scm_i_string_chars (option_name), - "%s", - scm_i_string_chars (value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_write: write configuration file - */ - -SCM -weechat_guile_api_config_write (SCM config_file) -{ - int rc; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - if (!scm_is_string (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_write (API_STR2PTR(scm_i_string_chars (config_file))); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_read: read configuration file - */ - -SCM -weechat_guile_api_config_read (SCM config_file) -{ - int rc; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - if (!scm_is_string (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_read (API_STR2PTR(scm_i_string_chars (config_file))); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_reload: reload configuration file - */ - -SCM -weechat_guile_api_config_reload (SCM config_file) -{ - int rc; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - if (!scm_is_string (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_reload (API_STR2PTR(scm_i_string_chars (config_file))); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_option_free: free an option in configuration file - */ - -SCM -weechat_guile_api_config_option_free (SCM option) -{ - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_option_free (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (option))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_section_free_options: free all options of a section - * in configuration file - */ - -SCM -weechat_guile_api_config_section_free_options (SCM section) -{ - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - if (!scm_is_string (section)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free_options (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (section))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_section_free: free section in configuration file - */ - -SCM -weechat_guile_api_config_section_free (SCM section) -{ - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - if (!scm_is_string (section)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (section))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_free: free configuration file - */ - -SCM -weechat_guile_api_config_free (SCM config_file) -{ - API_FUNC(1, "config_free", API_RETURN_ERROR); - if (!scm_is_string (config_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_free (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (config_file))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_get: get config option - */ - -SCM -weechat_guile_api_config_get (SCM option) -{ - char *result; - SCM return_value; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_get (scm_i_string_chars (option))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_config_get_plugin: get value of a plugin option - */ - -SCM -weechat_guile_api_config_get_plugin (SCM option) -{ - const char *result; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_api_config_get_plugin (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_config_is_set_plugin: check if a plugin option is set - */ - -SCM -weechat_guile_api_config_is_set_plugin (SCM option) -{ - int rc; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = script_api_config_is_set_plugin (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_set_plugin: set value of a plugin option - */ - -SCM -weechat_guile_api_config_set_plugin (SCM option, SCM value) -{ - int rc; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (!scm_is_string (option) || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = script_api_config_set_plugin (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option), - scm_i_string_chars (value)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_config_set_desc_plugin: set description of a plugin option - */ - -SCM -weechat_guile_api_config_set_desc_plugin (SCM option, SCM description) -{ - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - if (!scm_is_string (option) || !scm_is_string (description)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_set_desc_plugin (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option), - scm_i_string_chars (description)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_config_unset_plugin: unset plugin option - */ - -SCM -weechat_guile_api_config_unset_plugin (SCM option) -{ - int rc; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (!scm_is_string (option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - rc = script_api_config_unset_plugin (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_key_bind: bind key(s) - */ - -SCM -weechat_guile_api_key_bind (SCM context, SCM keys) -{ - struct t_hashtable *c_keys; - int num_keys; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - if (!scm_is_string (context) || !scm_list_p (keys)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - c_keys = weechat_guile_alist_to_hashtable (keys, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (scm_i_string_chars (context), c_keys); - - if (c_keys) - weechat_hashtable_free (c_keys); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_guile_api_key_unbind: unbind key(s) - */ - -SCM -weechat_guile_api_key_unbind (SCM context, SCM key) -{ - int num_keys; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - if (!scm_is_string (context) || !scm_is_string (key)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - num_keys = weechat_key_unbind (scm_i_string_chars (context), - scm_i_string_chars (key)); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_guile_api_prefix: get a prefix, used for display - */ - -SCM -weechat_guile_api_prefix (SCM prefix) -{ - const char *result; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - if (!scm_is_string (prefix)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_prefix (scm_i_string_chars (prefix)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_color: get a color code, used for display - */ - -SCM -weechat_guile_api_color (SCM color) -{ - const char *result; - - API_FUNC(0, "color", API_RETURN_EMPTY); - if (!scm_is_string (color)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_color (scm_i_string_chars (color)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_print: print message in a buffer - */ - -SCM -weechat_guile_api_print (SCM buffer, SCM message) -{ - API_FUNC(0, "print", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer)), - "%s", scm_i_string_chars (message)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_print_date_tags: print message in a buffer with optional - * date and tags - */ - -SCM -weechat_guile_api_print_date_tags (SCM buffer, SCM date, SCM tags, SCM message) -{ - API_FUNC(1, "print_date_tags", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_integer (date) - || !scm_is_string (tags) || !scm_is_string (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf_date_tags (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer)), - scm_to_int (date), - scm_i_string_chars (tags), - "%s", scm_i_string_chars (message)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_print_y: print message in a buffer with free content - */ - -SCM -weechat_guile_api_print_y (SCM buffer, SCM y, SCM message) -{ - API_FUNC(1, "print_y", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_integer (y) - || !scm_is_string (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf_y (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer)), - scm_to_int (y), - "%s", scm_i_string_chars (message)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_log_print: print message in WeeChat log file - */ - -SCM -weechat_guile_api_log_print (SCM message) -{ - API_FUNC(1, "log_print", API_RETURN_ERROR); - if (!scm_is_string (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_log_printf (weechat_guile_plugin, - guile_current_script, - "%s", scm_i_string_chars (message)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_hook_command_cb: callback for command hooked - */ - -int -weechat_guile_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_command: hook a command - */ - -SCM -weechat_guile_api_hook_command (SCM command, SCM description, SCM args, - SCM args_description, SCM completion, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - if (!scm_is_string (command) || !scm_is_string (description) - || !scm_is_string (args) || !scm_is_string (args_description) - || !scm_is_string (completion) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_ERROR); - - result = script_ptr2str (script_api_hook_command (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (command), - scm_i_string_chars (description), - scm_i_string_chars (args), - scm_i_string_chars (args_description), - scm_i_string_chars (completion), - &weechat_guile_api_hook_command_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_guile_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_command_run: hook a command_run - */ - -SCM -weechat_guile_api_hook_command_run (SCM command, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - if (!scm_is_string (command) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_command_run (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (command), - &weechat_guile_api_hook_command_run_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_guile_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_timer: hook a timer - */ - -SCM -weechat_guile_api_hook_timer (SCM interval, SCM align_second, SCM max_calls, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - if (!scm_is_integer (interval) || !scm_is_integer (align_second) - || !scm_is_integer (max_calls) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_timer (weechat_guile_plugin, - guile_current_script, - scm_to_int (interval), - scm_to_int (align_second), - scm_to_int (max_calls), - &weechat_guile_api_hook_timer_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_guile_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_fd: hook a fd - */ - -SCM -weechat_guile_api_hook_fd (SCM fd, SCM read, SCM write, SCM exception, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - if (!scm_is_integer (fd) || !scm_is_integer (read) - || !scm_is_integer (write) || !scm_is_integer (exception) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_fd (weechat_guile_plugin, - guile_current_script, - scm_to_int (fd), - scm_to_int (read), - scm_to_int (write), - scm_to_int (exception), - &weechat_guile_api_hook_fd_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_process_cb: callback for process hooked - */ - -int -weechat_guile_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = &return_code; - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssiss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_process: hook a process - */ - -SCM -weechat_guile_api_hook_process (SCM command, SCM timeout, SCM function, - SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - if (!scm_is_string (command) || !scm_is_integer (timeout) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_process (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (command), - scm_to_int (timeout), - &weechat_guile_api_hook_process_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_process_hashtable: hook a process with options in a - * hashtable - */ - -SCM -weechat_guile_api_hook_process_hashtable (SCM command, SCM options, SCM timeout, - SCM function, SCM data) -{ - char *result; - SCM return_value; - struct t_hashtable *c_options; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - if (!scm_is_string (command) || !scm_list_p (options) - || !scm_is_integer (timeout) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - c_options = weechat_guile_alist_to_hashtable (options, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (command), - c_options, - scm_to_int (timeout), - &weechat_guile_api_hook_process_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - if (c_options) - weechat_hashtable_free (c_options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_guile_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_connect: hook a connection - */ - -SCM -weechat_guile_api_hook_connect (SCM proxy, SCM address, SCM port, SCM sock, - SCM ipv6, SCM local_hostname, SCM function, - SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - if (!scm_is_string (proxy) || !scm_is_string (address) - || !scm_is_integer (port) || !scm_is_integer (sock) - || !scm_is_integer (ipv6) || !scm_is_string (local_hostname) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_connect (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (proxy), - scm_i_string_chars (address), - scm_to_int (port), - scm_to_int (sock), - scm_to_int (ipv6), - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - scm_i_string_chars (local_hostname), - &weechat_guile_api_hook_connect_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_print_cb: callback for print hooked - */ - -int -weechat_guile_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_print: hook a print - */ - -SCM -weechat_guile_api_hook_print (SCM buffer, SCM tags, SCM message, - SCM strip_colors, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (tags) - || !scm_is_string (message) || !scm_is_integer (strip_colors) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_print (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (tags), - scm_i_string_chars (message), - scm_to_int (strip_colors), - &weechat_guile_api_hook_print_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_guile_api_hook_signal_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_signal: hook a signal - */ - -SCM -weechat_guile_api_hook_signal (SCM signal, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - if (!scm_is_string (signal) || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_signal (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (signal), - &weechat_guile_api_hook_signal_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_signal_send: send a signal - */ - -SCM -weechat_guile_api_hook_signal_send (SCM signal, SCM type_data, - SCM signal_data) -{ - int number; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - if (!scm_is_string (signal) || !scm_is_string (type_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (strcmp (scm_i_string_chars (type_data), WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (!scm_is_string (signal_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - weechat_hook_signal_send (scm_i_string_chars (signal), - scm_i_string_chars (type_data), - (void *)scm_i_string_chars (signal_data)); - API_RETURN_OK; - } - else if (strcmp (scm_i_string_chars (type_data), WEECHAT_HOOK_SIGNAL_INT) == 0) - { - if (!scm_is_integer (signal_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - number = scm_to_int (signal_data); - weechat_hook_signal_send (scm_i_string_chars (signal), - scm_i_string_chars (type_data), - &number); - API_RETURN_OK; - } - else if (strcmp (scm_i_string_chars (type_data), WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - if (!scm_is_string (signal_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - weechat_hook_signal_send (scm_i_string_chars (signal), - scm_i_string_chars (type_data), - API_STR2PTR(scm_i_string_chars (signal_data))); - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_guile_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_guile_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = hashtable; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssh", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_hsignal: hook a hsignal - */ - -SCM -weechat_guile_api_hook_hsignal (SCM signal, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - if (!scm_is_string (signal) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_hsignal (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (signal), - &weechat_guile_api_hook_hsignal_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_hsignal_send: send a hsignal - */ - -SCM -weechat_guile_api_hook_hsignal_send (SCM signal, SCM hashtable) -{ - struct t_hashtable *c_hashtable; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - if (!scm_is_string (signal) || !scm_list_p (hashtable)) - API_WRONG_ARGS(API_RETURN_ERROR); - - c_hashtable = weechat_guile_alist_to_hashtable (hashtable, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (scm_i_string_chars (signal), c_hashtable); - - if (c_hashtable) - weechat_hashtable_free (c_hashtable); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_guile_api_hook_config_cb (void *data, const char *option, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_config: hook a config option - */ - -SCM -weechat_guile_api_hook_config (SCM option, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - if (!scm_is_string (option) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_config (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (option), - &weechat_guile_api_hook_config_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_guile_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_hook_completion: hook a completion - */ - -SCM -weechat_guile_api_hook_completion (SCM completion, SCM description, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (!scm_is_string (completion) || !scm_is_string (description) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_completion (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (completion), - scm_i_string_chars (description), - &weechat_guile_api_hook_completion_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_completion_list_add: add a word to list for a completion - */ - -SCM -weechat_guile_api_hook_completion_list_add (SCM completion, SCM word, - SCM nick_completion, SCM where) -{ - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (!scm_is_string (completion) || !scm_is_string (word) - || !scm_is_integer (nick_completion) || !scm_is_string (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(scm_i_string_chars (completion)), - scm_i_string_chars (word), - scm_to_int (nick_completion), - scm_i_string_chars (where)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_guile_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat_guile_api_hook_modifier: hook a modifier - */ - -SCM -weechat_guile_api_hook_modifier (SCM modifier, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - if (!scm_is_string (modifier) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_modifier (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (modifier), - &weechat_guile_api_hook_modifier_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_modifier_exec: execute a modifier hook - */ - -SCM -weechat_guile_api_hook_modifier_exec (SCM modifier, SCM modifier_data, - SCM string) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - if (!scm_is_string (modifier) || !scm_is_string (modifier_data) - || !scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_modifier_exec (scm_i_string_chars (modifier), - scm_i_string_chars (modifier_data), - scm_i_string_chars (string)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_guile_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat_guile_api_hook_info: hook an info - */ - -SCM -weechat_guile_api_hook_info (SCM info_name, SCM description, - SCM args_description, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - if (!scm_is_string (info_name) || !scm_is_string (description) - || !scm_is_string (args_description) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_info (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (info_name), - scm_i_string_chars (description), - scm_i_string_chars (args_description), - &weechat_guile_api_hook_info_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_guile_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = hashtable; - - return (struct t_hashtable *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssh", func_argv); - } - - return NULL; -} - -/* - * weechat_guile_api_hook_info_hashtable: hook an info_hashtable - */ - -SCM -weechat_guile_api_hook_info_hashtable (SCM info_name, SCM description, - SCM args_description, - SCM output_description, SCM function, - SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - if (!scm_is_string (info_name) || !scm_is_string (description) - || !scm_is_string (args_description) || !scm_is_string (output_description) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (info_name), - scm_i_string_chars (description), - scm_i_string_chars (args_description), - scm_i_string_chars (output_description), - &weechat_guile_api_hook_info_hashtable_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_guile_api_hook_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat_guile_api_hook_infolist: hook an infolist - */ - -SCM -weechat_guile_api_hook_infolist (SCM infolist_name, SCM description, - SCM pointer_description, SCM args_description, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - if (!scm_is_string (infolist_name) || !scm_is_string (description) - || !scm_is_string (pointer_description) || !scm_is_string (args_description) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_infolist (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (infolist_name), - scm_i_string_chars (description), - scm_i_string_chars (pointer_description), - scm_i_string_chars (args_description), - &weechat_guile_api_hook_infolist_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_guile_api_hook_focus_cb (void *data, struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = info; - - return (struct t_hashtable *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sh", func_argv); - } - - return NULL; -} - -/* - * weechat_guile_api_hook_focus: hook a focus - */ - -SCM -weechat_guile_api_hook_focus (SCM area, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - if (!scm_is_string (area) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_focus (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (area), - &weechat_guile_api_hook_focus_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_unhook: unhook something - */ - -SCM -weechat_guile_api_unhook (SCM hook) -{ - API_FUNC(1, "unhook", API_RETURN_ERROR); - if (!scm_is_string (hook)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_unhook (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (hook))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_unhook_all: unhook all for script - */ - -SCM -weechat_guile_api_unhook_all () -{ - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_guile_plugin, guile_current_script); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_guile_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_buffer_close_cb: callback for closed buffer - */ - -int -weechat_guile_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_buffer_new: create a new buffer - */ - -SCM -weechat_guile_api_buffer_new (SCM name, SCM function_input, SCM data_input, - SCM function_close, SCM data_close) -{ - char *result; - SCM return_value; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - if (!scm_is_string (name) || !scm_is_string (function_input) - || !scm_is_string (data_input) || !scm_is_string (function_close) - || !scm_is_string (data_close)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_buffer_new (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (name), - &weechat_guile_api_buffer_input_data_cb, - scm_i_string_chars (function_input), - scm_i_string_chars (data_input), - &weechat_guile_api_buffer_close_cb, - scm_i_string_chars (function_close), - scm_i_string_chars (data_close))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_buffer_search: search a buffer - */ - -SCM -weechat_guile_api_buffer_search (SCM plugin, SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - if (!scm_is_string (plugin) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search (scm_i_string_chars (plugin), - scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_buffer_search_main: search main buffer (WeeChat core buffer) - */ - -SCM -weechat_guile_api_buffer_search_main () -{ - char *result; - SCM return_value; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_current_buffer: get current buffer - */ - -SCM -weechat_guile_api_current_buffer () -{ - char *result; - SCM return_value; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_buffer_clear: clear a buffer - */ - -SCM -weechat_guile_api_buffer_clear (SCM buffer) -{ - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - if (!scm_is_string (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_clear (API_STR2PTR(scm_i_string_chars (buffer))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_close: close a buffer - */ - -SCM -weechat_guile_api_buffer_close (SCM buffer) -{ - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - if (!scm_is_string (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_buffer_close (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_merge: merge a buffer to another buffer - */ - -SCM -weechat_guile_api_buffer_merge (SCM buffer, SCM target_buffer) -{ - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (target_buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_merge (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (target_buffer))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_unmerge: unmerge a buffer from a group of merged - * buffers - */ - -SCM -weechat_guile_api_buffer_unmerge (SCM buffer, SCM number) -{ - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_integer (number)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_unmerge (API_STR2PTR(scm_i_string_chars (buffer)), - scm_to_int (number)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_get_integer: get a buffer property as integer - */ - -SCM -weechat_guile_api_buffer_get_integer (SCM buffer, SCM property) -{ - int value; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - if (!scm_is_string (buffer) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_buffer_get_integer (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (property)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_buffer_get_string: get a buffer property as string - */ - -SCM -weechat_guile_api_buffer_get_string (SCM buffer, SCM property) -{ - const char *result; - - API_FUNC(1, "buffer_get_string", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_buffer_get_string (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (property)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_buffer_get_pointer: get a buffer property as pointer - */ - -SCM -weechat_guile_api_buffer_get_pointer (SCM buffer, SCM property) -{ - char *result; - SCM return_value; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (property))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_buffer_set: set a buffer property - */ - -SCM -weechat_guile_api_buffer_set (SCM buffer, SCM property, SCM value) -{ - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (property) - || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_set (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (property), - scm_i_string_chars (value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_buffer_string_replace_local_var: replace local variables - * ($var) in a string, using - * value of local variables - */ - -SCM -weechat_guile_api_buffer_string_replace_local_var (SCM buffer, SCM string) -{ - char *result; - SCM return_value; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_ERROR); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (string)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_buffer_match_list: return 1 if buffer matches list of buffers - */ - -SCM -weechat_guile_api_buffer_match_list (SCM buffer, SCM string) -{ - int value; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - if (!scm_is_string (buffer) || !scm_is_string (string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_buffer_match_list (API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (string)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_current_window: get current window - */ - -SCM -weechat_guile_api_current_window () -{ - char *result; - SCM return_value; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_window_search_with_buffer: search a window with buffer - * pointer - */ - -SCM -weechat_guile_api_window_search_with_buffer (SCM buffer) -{ - char *result; - SCM return_value; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - if (!scm_is_string (buffer)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(scm_i_string_chars (buffer)))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_window_get_integer: get a window property as integer - */ - -SCM -weechat_guile_api_window_get_integer (SCM window, SCM property) -{ - int value; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - if (!scm_is_string (window) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_window_get_integer (API_STR2PTR(scm_i_string_chars (window)), - scm_i_string_chars (property)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_window_get_string: get a window property as string - */ - -SCM -weechat_guile_api_window_get_string (SCM window, SCM property) -{ - const char *result; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - if (!scm_is_string (window) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_window_get_string (API_STR2PTR(scm_i_string_chars (window)), - scm_i_string_chars (property)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_window_get_pointer: get a window property as pointer - */ - -SCM -weechat_guile_api_window_get_pointer (SCM window, SCM property) -{ - char *result; - SCM return_value; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - if (!scm_is_string (window) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(scm_i_string_chars (window)), - scm_i_string_chars (property))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_window_set_title: set window title - */ - -SCM -weechat_guile_api_window_set_title (SCM title) -{ - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - if (!scm_is_string (title)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_window_set_title (scm_i_string_chars (title)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_nicklist_add_group: add a group in nicklist - */ - -SCM -weechat_guile_api_nicklist_add_group (SCM buffer, SCM parent_group, SCM name, - SCM color, SCM visible) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (parent_group) - || !scm_is_string (name) || !scm_is_string (color) - || !scm_is_integer (visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (parent_group)), - scm_i_string_chars (name), - scm_i_string_chars (color), - scm_to_int (visible))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_search_group: search a group in nicklist - */ - -SCM -weechat_guile_api_nicklist_search_group (SCM buffer, SCM from_group, SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (from_group) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (from_group)), - scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_add_nick: add a nick in nicklist - */ - -SCM -weechat_guile_api_nicklist_add_nick (SCM buffer, SCM group, SCM name, - SCM color, SCM prefix, SCM prefix_color, - SCM visible) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (group) - || !scm_is_string (name) || !scm_is_string (color) - || !scm_is_string (prefix) || !scm_is_string (prefix_color) - || !scm_is_integer (visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group)), - scm_i_string_chars (name), - scm_i_string_chars (color), - scm_i_string_chars (prefix), - scm_i_string_chars (prefix_color), - scm_to_int (visible))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_search_nick: search a nick in nicklist - */ - -SCM -weechat_guile_api_nicklist_search_nick (SCM buffer, SCM from_group, SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (from_group) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (from_group)), - scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_remove_group: remove a group from nicklist - */ - -SCM -weechat_guile_api_nicklist_remove_group (SCM buffer, SCM group) -{ - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (group)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_group (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_nicklist_remove_nick: remove a nick from nicklist - */ - -SCM -weechat_guile_api_nicklist_remove_nick (SCM buffer, SCM nick) -{ - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (nick)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_nick (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (nick))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_nicklist_remove_all: remove all groups/nicks from nicklist - */ - -SCM -weechat_guile_api_nicklist_remove_all (SCM buffer) -{ - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - if (!scm_is_string (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_all (API_STR2PTR(scm_i_string_chars (buffer))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_nicklist_group_get_integer: get a group property as integer - */ - -SCM -weechat_guile_api_nicklist_group_get_integer (SCM buffer, SCM group, - SCM property) -{ - int value; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - if (!scm_is_string (buffer) || !scm_is_string (group) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_nicklist_group_get_integer (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group)), - scm_i_string_chars (property)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_nicklist_group_get_string: get a group property as string - */ - -SCM -weechat_guile_api_nicklist_group_get_string (SCM buffer, SCM group, - SCM property) -{ - const char *result; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (group) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_nicklist_group_get_string (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group)), - scm_i_string_chars (property)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_nicklist_group_get_pointer: get a group property as pointer - */ - -SCM -weechat_guile_api_nicklist_group_get_pointer (SCM buffer, SCM group, - SCM property) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (group) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group)), - scm_i_string_chars (property))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_group_set: set a group property - */ - -SCM -weechat_guile_api_nicklist_group_set (SCM buffer, SCM group, SCM property, - SCM value) -{ - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (group) || !scm_is_string (property) || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_group_set (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (group)), - scm_i_string_chars (property), - scm_i_string_chars (value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_nicklist_nick_get_integer: get a nick property as integer - */ - -SCM -weechat_guile_api_nicklist_nick_get_integer (SCM buffer, SCM nick, SCM property) -{ - int value; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - if (!scm_is_string (buffer) || !scm_is_string (nick) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_nicklist_nick_get_integer (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (nick)), - scm_i_string_chars (property)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_nicklist_nick_get_string: get a nick property as string - */ - -SCM -weechat_guile_api_nicklist_nick_get_string (SCM buffer, SCM nick, SCM property) -{ - const char *result; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (nick) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (nick)), - scm_i_string_chars (property)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_nicklist_nick_get_pointer: get a nick property as pointer - */ - -SCM -weechat_guile_api_nicklist_nick_get_pointer (SCM buffer, SCM nick, SCM property) -{ - char *result; - SCM return_value; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - if (!scm_is_string (buffer) || !scm_is_string (nick) - || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (nick)), - scm_i_string_chars (property))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_nicklist_nick_set: set a nick property - */ - -SCM -weechat_guile_api_nicklist_nick_set (SCM buffer, SCM nick, SCM property, - SCM value) -{ - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (nick) - || !scm_is_string (property) || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_nick_set (API_STR2PTR(scm_i_string_chars (buffer)), - API_STR2PTR(scm_i_string_chars (nick)), - scm_i_string_chars (property), - scm_i_string_chars (value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_bar_item_search: search a bar item - */ - -SCM -weechat_guile_api_bar_item_search (SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - if (!scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_item_search (scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_guile_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat_guile_api_bar_item_new: add a new bar item - */ - -SCM -weechat_guile_api_bar_item_new (SCM name, SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - if (!scm_is_string (name) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_bar_item_new (weechat_guile_plugin, - guile_current_script, - scm_i_string_chars (name), - &weechat_guile_api_bar_item_build_cb, - scm_i_string_chars (function), - scm_i_string_chars (data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_bar_item_update: update a bar item on screen - */ - -SCM -weechat_guile_api_bar_item_update (SCM name) -{ - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - if (!scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_item_update (scm_i_string_chars (name)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_bar_item_remove: remove a bar item - */ - -SCM -weechat_guile_api_bar_item_remove (SCM item) -{ - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - if (!scm_is_string (item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_bar_item_remove (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (item))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_bar_search: search a bar - */ - -SCM -weechat_guile_api_bar_search (SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - if (!scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_search (scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_bar_new: add a new bar - */ - -SCM -weechat_guile_api_bar_new (SCM args) -{ - SCM name, hidden, priority, type, conditions, position, filling_top_bottom; - SCM filling_left_right, size, size_max, color_fg, color_delim, color_bg; - SCM separator, items; - char *result; - SCM return_value; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - if (!scm_list_p (args) || (scm_to_int (scm_length (args)) != 15)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = scm_list_ref (args, scm_from_int (0)); - hidden = scm_list_ref (args, scm_from_int (1)); - priority = scm_list_ref (args, scm_from_int (2)); - type = scm_list_ref (args, scm_from_int (3)); - conditions = scm_list_ref (args, scm_from_int (4)); - position = scm_list_ref (args, scm_from_int (5)); - filling_top_bottom = scm_list_ref (args, scm_from_int (6)); - filling_left_right = scm_list_ref (args, scm_from_int (7)); - size = scm_list_ref (args, scm_from_int (8)); - size_max = scm_list_ref (args, scm_from_int (9)); - color_fg = scm_list_ref (args, scm_from_int (10)); - color_delim = scm_list_ref (args, scm_from_int (11)); - color_bg = scm_list_ref (args, scm_from_int (12)); - separator = scm_list_ref (args, scm_from_int (13)); - items = scm_list_ref (args, scm_from_int (14)); - - if (!scm_is_string (name) || !scm_is_string (hidden) - || !scm_is_string (priority) || !scm_is_string (type) - || !scm_is_string (conditions) || !scm_is_string (position) - || !scm_is_string (filling_top_bottom) || !scm_is_string (filling_left_right) - || !scm_is_string (size) || !scm_is_string (size_max) - || !scm_is_string (color_fg) || !scm_is_string (color_delim) - || !scm_is_string (color_bg) || !scm_is_string (separator) - || !scm_is_string (items)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_new (scm_i_string_chars (name), - scm_i_string_chars (hidden), - scm_i_string_chars (priority), - scm_i_string_chars (type), - scm_i_string_chars (conditions), - scm_i_string_chars (position), - scm_i_string_chars (filling_top_bottom), - scm_i_string_chars (filling_left_right), - scm_i_string_chars (size), - scm_i_string_chars (size_max), - scm_i_string_chars (color_fg), - scm_i_string_chars (color_delim), - scm_i_string_chars (color_bg), - scm_i_string_chars (separator), - scm_i_string_chars (items))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_bar_set: set a bar property - */ - -SCM -weechat_guile_api_bar_set (SCM bar, SCM property, SCM value) -{ - API_FUNC(1, "bar_set", API_RETURN_ERROR); - if (!scm_is_string (bar) || !scm_is_string (property) - || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_set (API_STR2PTR(scm_i_string_chars (bar)), - scm_i_string_chars (property), - scm_i_string_chars (value)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_bar_update: update a bar on screen - */ - -SCM -weechat_guile_api_bar_update (SCM name) -{ - API_FUNC(1, "bar_update", API_RETURN_ERROR); - if (!scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_update (scm_i_string_chars (name)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_bar_remove: remove a bar - */ - -SCM -weechat_guile_api_bar_remove (SCM bar) -{ - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - if (!scm_is_string (bar)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_remove (API_STR2PTR(scm_i_string_chars (bar))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_command: send command to server - */ - -SCM -weechat_guile_api_command (SCM buffer, SCM command) -{ - API_FUNC(1, "command", API_RETURN_ERROR); - if (!scm_is_string (buffer) || !scm_is_string (command)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_command (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (buffer)), - scm_i_string_chars (command)); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_info_get: get info (as string) - */ - -SCM -weechat_guile_api_info_get (SCM info_name, SCM arguments) -{ - const char *result; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - if (!scm_is_string (info_name) || !scm_is_string (arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_info_get (scm_i_string_chars (info_name), - scm_i_string_chars (arguments)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_info_get_hashtable: get info (as hashtable) - */ - -SCM -weechat_guile_api_info_get_hashtable (SCM info_name, SCM hash) -{ - struct t_hashtable *c_hashtable, *result_hashtable; - SCM result_alist; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - if (!scm_is_string (info_name) || !scm_list_p (hash)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - c_hashtable = weechat_guile_alist_to_hashtable (hash, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (scm_i_string_chars (info_name), - c_hashtable); - result_alist = weechat_guile_hashtable_to_alist (result_hashtable); - - if (c_hashtable) - weechat_hashtable_free (c_hashtable); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - return result_alist; -} - -/* - * weechat_guile_api_infolist_new: create new infolist - */ - -SCM -weechat_guile_api_infolist_new () -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_new_item: create new item in infolist - */ - -SCM -weechat_guile_api_infolist_new_item (SCM infolist) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new_item", API_RETURN_EMPTY); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(scm_i_string_chars (infolist)))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_new_var_integer: create new integer variable in - * infolist - */ - -SCM -weechat_guile_api_infolist_new_var_integer (SCM infolist, SCM name, SCM value) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (name) - || !scm_is_integer (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (name), - scm_to_int (value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_new_var_string: create new string variable in - * infolist - */ - -SCM -weechat_guile_api_infolist_new_var_string (SCM infolist, SCM name, SCM value) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (name) - || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (name), - scm_i_string_chars (value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_new_var_pointer: create new pointer variable in - * infolist - */ - -SCM -weechat_guile_api_infolist_new_var_pointer (SCM infolist, SCM name, SCM value) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (name) - || !scm_is_string (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (name), - API_STR2PTR(scm_i_string_chars (value)))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_new_var_time: create new time variable in infolist - */ - -SCM -weechat_guile_api_infolist_new_var_time (SCM infolist, SCM name, SCM value) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (name) - || !scm_is_integer (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (name), - scm_to_int (value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_get: get list with infos - */ - -SCM -weechat_guile_api_infolist_get (SCM name, SCM pointer, SCM arguments) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - if (!scm_is_string (name) || !scm_is_string (pointer) - || !scm_is_string (arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_get (scm_i_string_chars (name), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (arguments))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_next: move item pointer to next item in infolist - */ - -SCM -weechat_guile_api_infolist_next (SCM infolist) -{ - int value; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_next (API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_infolist_prev: move item pointer to previous item in - * infolist - */ - -SCM -weechat_guile_api_infolist_prev (SCM infolist) -{ - int value; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_prev (API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_infolist_reset_item_cursor: reset pointer to current item - * in infolist - */ - -SCM -weechat_guile_api_infolist_reset_item_cursor (SCM infolist) -{ - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_reset_item_cursor (API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_infolist_fields: get list of fields for current item of infolist - */ - -SCM -weechat_guile_api_infolist_fields (SCM infolist) -{ - const char *result; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_fields (API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_infolist_integer: get integer value of a variable in - * infolist - */ - -SCM -weechat_guile_api_infolist_integer (SCM infolist, SCM variable) -{ - int value; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - if (!scm_is_string (infolist) || !scm_is_string (variable)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_integer (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (variable)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_infolist_string: get string value of a variable in infolist - */ - -SCM -weechat_guile_api_infolist_string (SCM infolist, SCM variable) -{ - const char *result; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_string (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (variable)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_infolist_pointer: get pointer value of a variable in - * infolist - */ - -SCM -weechat_guile_api_infolist_pointer (SCM infolist, SCM variable) -{ - char *result; - SCM return_value; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (variable))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_time: get time value of a variable in infolist - */ - -SCM -weechat_guile_api_infolist_time (SCM infolist, SCM variable) -{ - char timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - SCM return_value; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - if (!scm_is_string (infolist) || !scm_is_string (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(scm_i_string_chars (infolist)), - scm_i_string_chars (variable)); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_infolist_free: free infolist - */ - -SCM -weechat_guile_api_infolist_free (SCM infolist) -{ - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - if (!scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_free (API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_hdata_get: get hdata - */ - -SCM -weechat_guile_api_hdata_get (SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - if (!scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_get (scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hdata_get_var_offset: get offset of variable in hdata - */ - -SCM -weechat_guile_api_hdata_get_var_offset (SCM hdata, SCM name) -{ - int value; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - if (!scm_is_string (hdata) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_get_var_offset (API_STR2PTR(scm_i_string_chars (hdata)), - scm_i_string_chars (name)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_hdata_get_var_type_string: get type of variable as string - * in hdata - */ - -SCM -weechat_guile_api_hdata_get_var_type_string (SCM hdata, SCM name) -{ - const char *result; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(scm_i_string_chars (hdata)), - scm_i_string_chars (name)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_hdata_get_var_array_size: get array size for variable in - * hdata - */ - -SCM -weechat_guile_api_hdata_get_var_array_size (SCM hdata, SCM pointer, SCM name) -{ - int value; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_hdata_get_var_array_size (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_hdata_get_var_array_size_string: get array size for variable - * in hdata (as string) - */ - -SCM -weechat_guile_api_hdata_get_var_array_size_string (SCM hdata, SCM pointer, - SCM name) -{ - const char *result; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_hdata_get_var_hdata: get hdata for variable in hdata - */ - -SCM -weechat_guile_api_hdata_get_var_hdata (SCM hdata, SCM name) -{ - const char *result; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(scm_i_string_chars (hdata)), - scm_i_string_chars (name)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_hdata_get_list: get list pointer in hdata - */ - -SCM -weechat_guile_api_hdata_get_list (SCM hdata, SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(scm_i_string_chars (hdata)), - scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hdata_check_pointer: check pointer with hdata/list - */ - -SCM -weechat_guile_api_hdata_check_pointer (SCM hdata, SCM list, SCM pointer) -{ - int value; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - if (!scm_is_string (hdata) || !scm_is_string (list) - || !scm_is_string (pointer)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_check_pointer (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (list)), - API_STR2PTR(scm_i_string_chars (pointer))); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_hdata_move: move pointer to another element in list - */ - -SCM -weechat_guile_api_hdata_move (SCM hdata, SCM pointer, SCM count) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_integer (count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_move (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_to_int (count)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hdata_char: get char value of a variable in structure - * using hdata - */ - -SCM -weechat_guile_api_hdata_char (SCM hdata, SCM pointer, SCM name) -{ - int value; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = (int)weechat_hdata_char (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_hdata_integer: get integer value of a variable in structure - * using hdata - */ - -SCM -weechat_guile_api_hdata_integer (SCM hdata, SCM pointer, SCM name) -{ - int value; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_integer (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_INT(value); -} - -/* - * weechat_guile_api_hdata_long: get long value of a variable in structure using - * hdata - */ - -SCM -weechat_guile_api_hdata_long (SCM hdata, SCM pointer, SCM name) -{ - long value; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - value = weechat_hdata_long (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_LONG(value); -} - -/* - * weechat_guile_api_hdata_string: get string value of a variable in structure - * using hdata - */ - -SCM -weechat_guile_api_hdata_string (SCM hdata, SCM pointer, SCM name) -{ - const char *result; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_string (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_hdata_pointer: get pointer value of a variable in structure - * using hdata - */ - -SCM -weechat_guile_api_hdata_pointer (SCM hdata, SCM pointer, SCM name) -{ - char *result; - SCM return_value; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hdata_time: get time value of a variable in structure using - * hdata - */ - -SCM -weechat_guile_api_hdata_time (SCM hdata, SCM pointer, SCM name) -{ - char timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - SCM return_value; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name)); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_hdata_hashtable: get hashtable value of a variable in - * structure using hdata - */ - -SCM -weechat_guile_api_hdata_hashtable (SCM hdata, SCM pointer, SCM name) -{ - SCM result_alist; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result_alist = weechat_guile_hashtable_to_alist ( - weechat_hdata_hashtable (API_STR2PTR(scm_i_string_chars (hdata)), - API_STR2PTR(scm_i_string_chars (pointer)), - scm_i_string_chars (name))); - - return result_alist; -} - -/* - * weechat_guile_api_hdata_get_string: get hdata property as string - */ - -SCM -weechat_guile_api_hdata_get_string (SCM hdata, SCM property) -{ - const char *result; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - if (!scm_is_string (hdata) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(scm_i_string_chars (hdata)), - scm_i_string_chars (property)); - - API_RETURN_STRING(result); -} - -/* - * weechat_guile_api_upgrade_new: create an upgrade file - */ - -SCM -weechat_guile_api_upgrade_new (SCM filename, SCM write) -{ - char *result; - SCM return_value; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - if (!scm_is_string (filename) || !scm_is_integer (write)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_upgrade_new (scm_i_string_chars (filename), - scm_to_int (write))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_guile_api_upgrade_write_object: write object in upgrade file - */ - -SCM -weechat_guile_api_upgrade_write_object (SCM upgrade_file, SCM object_id, - SCM infolist) -{ - int rc; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - if (!scm_is_string (upgrade_file) || !scm_is_integer (object_id) - || !scm_is_string (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = weechat_upgrade_write_object (API_STR2PTR(scm_i_string_chars (upgrade_file)), - scm_to_int (object_id), - API_STR2PTR(scm_i_string_chars (infolist))); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_upgrade_read_cb: callback for reading object in upgrade - * file - */ - -int -weechat_guile_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_guile_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_guile_api_upgrade_read: read upgrade file - */ - -SCM -weechat_guile_api_upgrade_read (SCM upgrade_file, SCM function, SCM data) -{ - int rc; - - API_FUNC(1, "upgrade_read", API_RETURN_INT(0)); - if (!scm_is_string (upgrade_file) || !scm_is_string (function) - || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = script_api_upgrade_read (weechat_guile_plugin, - guile_current_script, - API_STR2PTR(scm_i_string_chars (upgrade_file)), - &weechat_guile_api_upgrade_read_cb, - scm_i_string_chars (function), - scm_i_string_chars (data)); - - API_RETURN_INT(rc); -} - -/* - * weechat_guile_api_upgrade_close: close upgrade file - */ - -SCM -weechat_guile_api_upgrade_close (SCM upgrade_file) -{ - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - if (!scm_is_string (upgrade_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_upgrade_close (API_STR2PTR(scm_i_string_chars (upgrade_file))); - - API_RETURN_OK; -} - -/* - * weechat_guile_api_module_init: init main module with API - */ - -void -weechat_guile_api_module_init (void *data) -{ - scm_t_bits port_type; - - /* make C compiler happy */ - (void) data; - - port_type = scm_make_port_type ("weechat_stdout", - &weechat_guile_port_fill_input, - &weechat_guile_port_write); - guile_port = scm_new_port_table_entry (port_type); - SCM_SET_CELL_TYPE (guile_port, port_type | SCM_OPN | SCM_WRTNG); - scm_set_current_output_port (guile_port); - scm_set_current_error_port (guile_port); - - /* interface functions */ - API_DEF_FUNC(register, 7); - API_DEF_FUNC(plugin_get_name, 1); - API_DEF_FUNC(charset_set, 1); - API_DEF_FUNC(iconv_to_internal, 2); - API_DEF_FUNC(iconv_from_internal, 2); - API_DEF_FUNC(gettext, 1); - API_DEF_FUNC(ngettext, 3); - API_DEF_FUNC(string_match, 3); - API_DEF_FUNC(string_has_highlight, 2); - API_DEF_FUNC(string_has_highlight_regex, 2); - API_DEF_FUNC(string_mask_to_regex, 1); - API_DEF_FUNC(string_remove_color, 2); - API_DEF_FUNC(string_is_command_char, 1); - API_DEF_FUNC(string_input_for_buffer, 1); - API_DEF_FUNC(mkdir_home, 2); - API_DEF_FUNC(mkdir, 2); - API_DEF_FUNC(mkdir_parents, 2); - API_DEF_FUNC(list_new, 0); - API_DEF_FUNC(list_add, 4); - API_DEF_FUNC(list_search, 2); - API_DEF_FUNC(list_search_pos, 2); - API_DEF_FUNC(list_casesearch, 2); - API_DEF_FUNC(list_casesearch_pos, 2); - API_DEF_FUNC(list_get, 2); - API_DEF_FUNC(list_set, 2); - API_DEF_FUNC(list_next, 1); - API_DEF_FUNC(list_prev, 1); - API_DEF_FUNC(list_string, 1); - API_DEF_FUNC(list_size, 1); - API_DEF_FUNC(list_remove, 2); - API_DEF_FUNC(list_remove_all, 1); - API_DEF_FUNC(list_free, 1); - API_DEF_FUNC(config_new, 3); - API_DEF_FUNC(config_new_section, 1); - API_DEF_FUNC(config_search_section, 2); - API_DEF_FUNC(config_new_option, 1); - API_DEF_FUNC(config_search_option, 3); - API_DEF_FUNC(config_string_to_boolean, 1); - API_DEF_FUNC(config_option_reset, 2); - API_DEF_FUNC(config_option_set, 3); - API_DEF_FUNC(config_option_set_null, 2); - API_DEF_FUNC(config_option_unset, 1); - API_DEF_FUNC(config_option_rename, 2); - API_DEF_FUNC(config_option_is_null, 1); - API_DEF_FUNC(config_option_default_is_null, 1); - API_DEF_FUNC(config_boolean, 1); - API_DEF_FUNC(config_boolean_default, 1); - API_DEF_FUNC(config_integer, 1); - API_DEF_FUNC(config_integer_default, 1); - API_DEF_FUNC(config_string, 1); - API_DEF_FUNC(config_string_default, 1); - API_DEF_FUNC(config_color, 1); - API_DEF_FUNC(config_color_default, 1); - API_DEF_FUNC(config_write_option, 2); - API_DEF_FUNC(config_write_line, 3); - API_DEF_FUNC(config_write, 1); - API_DEF_FUNC(config_read, 1); - API_DEF_FUNC(config_reload, 1); - API_DEF_FUNC(config_option_free, 1); - API_DEF_FUNC(config_section_free_options, 1); - API_DEF_FUNC(config_section_free, 1); - API_DEF_FUNC(config_free, 1); - API_DEF_FUNC(config_get, 1); - API_DEF_FUNC(config_get_plugin, 1); - API_DEF_FUNC(config_is_set_plugin, 1); - API_DEF_FUNC(config_set_plugin, 2); - API_DEF_FUNC(config_set_desc_plugin, 2); - API_DEF_FUNC(config_unset_plugin, 1); - API_DEF_FUNC(key_bind, 2); - API_DEF_FUNC(key_unbind, 2); - API_DEF_FUNC(prefix, 1); - API_DEF_FUNC(color, 1); - API_DEF_FUNC(print, 2); - API_DEF_FUNC(print_date_tags, 4); - API_DEF_FUNC(print_y, 3); - API_DEF_FUNC(log_print, 1); - API_DEF_FUNC(hook_command, 7); - API_DEF_FUNC(hook_command_run, 3); - API_DEF_FUNC(hook_timer, 5); - API_DEF_FUNC(hook_fd, 6); - API_DEF_FUNC(hook_process, 4); - API_DEF_FUNC(hook_process_hashtable, 5); - API_DEF_FUNC(hook_connect, 8); - API_DEF_FUNC(hook_print, 6); - API_DEF_FUNC(hook_signal, 3); - API_DEF_FUNC(hook_signal_send, 3); - API_DEF_FUNC(hook_hsignal, 3); - API_DEF_FUNC(hook_hsignal_send, 2); - API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_list_add, 4); - API_DEF_FUNC(hook_modifier, 3); - API_DEF_FUNC(hook_modifier_exec, 3); - API_DEF_FUNC(hook_info, 5); - API_DEF_FUNC(hook_info_hashtable, 6); - API_DEF_FUNC(hook_infolist, 6); - API_DEF_FUNC(hook_focus, 3); - API_DEF_FUNC(unhook, 1); - API_DEF_FUNC(unhook_all, 0); - API_DEF_FUNC(buffer_new, 5); - API_DEF_FUNC(buffer_search, 2); - API_DEF_FUNC(buffer_search_main, 0); - API_DEF_FUNC(current_buffer, 0); - API_DEF_FUNC(buffer_clear, 1); - API_DEF_FUNC(buffer_close, 1); - API_DEF_FUNC(buffer_merge, 2); - API_DEF_FUNC(buffer_unmerge, 2); - API_DEF_FUNC(buffer_get_integer, 2); - API_DEF_FUNC(buffer_get_string, 2); - API_DEF_FUNC(buffer_get_pointer, 2); - API_DEF_FUNC(buffer_set, 3); - API_DEF_FUNC(buffer_string_replace_local_var, 2); - API_DEF_FUNC(buffer_match_list, 2); - API_DEF_FUNC(current_window, 0); - API_DEF_FUNC(window_search_with_buffer, 1); - API_DEF_FUNC(window_get_integer, 2); - API_DEF_FUNC(window_get_string, 2); - API_DEF_FUNC(window_get_pointer, 2); - API_DEF_FUNC(window_set_title, 1); - API_DEF_FUNC(nicklist_add_group, 5); - API_DEF_FUNC(nicklist_search_group, 3); - API_DEF_FUNC(nicklist_add_nick, 7); - API_DEF_FUNC(nicklist_search_nick, 3); - API_DEF_FUNC(nicklist_remove_group, 2); - API_DEF_FUNC(nicklist_remove_nick, 2); - API_DEF_FUNC(nicklist_remove_all, 1); - API_DEF_FUNC(nicklist_group_get_integer, 3); - API_DEF_FUNC(nicklist_group_get_string, 3); - API_DEF_FUNC(nicklist_group_get_pointer, 3); - API_DEF_FUNC(nicklist_group_set, 4); - API_DEF_FUNC(nicklist_nick_get_integer, 3); - API_DEF_FUNC(nicklist_nick_get_string, 3); - API_DEF_FUNC(nicklist_nick_get_pointer, 3); - API_DEF_FUNC(nicklist_nick_set, 4); - API_DEF_FUNC(bar_item_search, 1); - API_DEF_FUNC(bar_item_new, 3); - API_DEF_FUNC(bar_item_update, 1); - API_DEF_FUNC(bar_item_remove, 1); - API_DEF_FUNC(bar_search, 1); - API_DEF_FUNC(bar_new, 1); - API_DEF_FUNC(bar_set, 3); - API_DEF_FUNC(bar_update, 1); - API_DEF_FUNC(bar_remove, 1); - API_DEF_FUNC(command, 2); - API_DEF_FUNC(info_get, 2); - API_DEF_FUNC(info_get_hashtable, 2); - API_DEF_FUNC(infolist_new, 0); - API_DEF_FUNC(infolist_new_item, 1); - API_DEF_FUNC(infolist_new_var_integer, 3); - API_DEF_FUNC(infolist_new_var_string, 3); - API_DEF_FUNC(infolist_new_var_pointer, 3); - API_DEF_FUNC(infolist_new_var_time, 3); - API_DEF_FUNC(infolist_get, 3); - API_DEF_FUNC(infolist_next, 1); - API_DEF_FUNC(infolist_prev, 1); - API_DEF_FUNC(infolist_reset_item_cursor, 1); - API_DEF_FUNC(infolist_fields, 1); - API_DEF_FUNC(infolist_integer, 2); - API_DEF_FUNC(infolist_string, 2); - API_DEF_FUNC(infolist_pointer, 2); - API_DEF_FUNC(infolist_time, 2); - API_DEF_FUNC(infolist_free, 1); - API_DEF_FUNC(hdata_get, 1); - API_DEF_FUNC(hdata_get_var_offset, 2); - API_DEF_FUNC(hdata_get_var_type_string, 2); - API_DEF_FUNC(hdata_get_var_array_size, 3); - API_DEF_FUNC(hdata_get_var_array_size_string, 3); - API_DEF_FUNC(hdata_get_var_hdata, 2); - API_DEF_FUNC(hdata_get_list, 2); - API_DEF_FUNC(hdata_check_pointer, 3); - API_DEF_FUNC(hdata_move, 3); - API_DEF_FUNC(hdata_char, 3); - API_DEF_FUNC(hdata_integer, 3); - API_DEF_FUNC(hdata_long, 3); - API_DEF_FUNC(hdata_string, 3); - API_DEF_FUNC(hdata_pointer, 3); - API_DEF_FUNC(hdata_time, 3); - API_DEF_FUNC(hdata_hashtable, 3); - API_DEF_FUNC(hdata_get_string, 2); - API_DEF_FUNC(upgrade_new, 2); - API_DEF_FUNC(upgrade_write_object, 3); - API_DEF_FUNC(upgrade_read, 3); - API_DEF_FUNC(upgrade_close, 1); - - /* interface constants */ - scm_c_define ("weechat:WEECHAT_RC_OK", scm_from_int (WEECHAT_RC_OK)); - scm_c_define ("weechat:WEECHAT_RC_OK_EAT", scm_from_int (WEECHAT_RC_OK_EAT)); - scm_c_define ("weechat:WEECHAT_RC_ERROR", scm_from_int (WEECHAT_RC_ERROR)); - - scm_c_define ("weechat:WEECHAT_CONFIG_READ_OK", scm_from_int (WEECHAT_CONFIG_READ_OK)); - scm_c_define ("weechat:WEECHAT_CONFIG_READ_MEMORY_ERROR", scm_from_int (WEECHAT_CONFIG_READ_MEMORY_ERROR)); - scm_c_define ("weechat:WEECHAT_CONFIG_READ_FILE_NOT_FOUND", scm_from_int (WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); - scm_c_define ("weechat:WEECHAT_CONFIG_WRITE_OK", scm_from_int (WEECHAT_CONFIG_WRITE_OK)); - scm_c_define ("weechat:WEECHAT_CONFIG_WRITE_ERROR", scm_from_int (WEECHAT_CONFIG_WRITE_ERROR)); - scm_c_define ("weechat:WEECHAT_CONFIG_WRITE_MEMORY_ERROR", scm_from_int (WEECHAT_CONFIG_WRITE_MEMORY_ERROR)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", scm_from_int (WEECHAT_CONFIG_OPTION_SET_OK_CHANGED)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", scm_from_int (WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_SET_ERROR", scm_from_int (WEECHAT_CONFIG_OPTION_SET_ERROR)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", scm_from_int (WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", scm_from_int (WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", scm_from_int (WEECHAT_CONFIG_OPTION_UNSET_OK_RESET)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", scm_from_int (WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)); - scm_c_define ("weechat:WEECHAT_CONFIG_OPTION_UNSET_ERROR", scm_from_int (WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - scm_c_define ("weechat:WEECHAT_LIST_POS_SORT", scm_from_locale_string (WEECHAT_LIST_POS_SORT)); - scm_c_define ("weechat:WEECHAT_LIST_POS_BEGINNING", scm_from_locale_string (WEECHAT_LIST_POS_BEGINNING)); - scm_c_define ("weechat:WEECHAT_LIST_POS_END", scm_from_locale_string (WEECHAT_LIST_POS_END)); - - scm_c_define ("weechat:WEECHAT_HOTLIST_LOW", scm_from_locale_string (WEECHAT_HOTLIST_LOW)); - scm_c_define ("weechat:WEECHAT_HOTLIST_MESSAGE", scm_from_locale_string (WEECHAT_HOTLIST_MESSAGE)); - scm_c_define ("weechat:WEECHAT_HOTLIST_PRIVATE", scm_from_locale_string (WEECHAT_HOTLIST_PRIVATE)); - scm_c_define ("weechat:WEECHAT_HOTLIST_HIGHLIGHT", scm_from_locale_string (WEECHAT_HOTLIST_HIGHLIGHT)); - - scm_c_define ("weechat:WEECHAT_HOOK_PROCESS_RUNNING", scm_from_int (WEECHAT_HOOK_PROCESS_RUNNING)); - scm_c_define ("weechat:WEECHAT_HOOK_PROCESS_ERROR", scm_from_int (WEECHAT_HOOK_PROCESS_ERROR)); - - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_OK", scm_from_int (WEECHAT_HOOK_CONNECT_OK)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", scm_from_int (WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", scm_from_int (WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", scm_from_int (WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_PROXY_ERROR", scm_from_int (WEECHAT_HOOK_CONNECT_PROXY_ERROR)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", scm_from_int (WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", scm_from_int (WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", scm_from_int (WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_MEMORY_ERROR", scm_from_int (WEECHAT_HOOK_CONNECT_MEMORY_ERROR)); - scm_c_define ("weechat:WEECHAT_HOOK_CONNECT_TIMEOUT", scm_from_int (WEECHAT_HOOK_CONNECT_TIMEOUT)); - - scm_c_define ("weechat:WEECHAT_HOOK_SIGNAL_STRING", scm_from_locale_string (WEECHAT_HOOK_SIGNAL_STRING)); - scm_c_define ("weechat:WEECHAT_HOOK_SIGNAL_INT", scm_from_locale_string (WEECHAT_HOOK_SIGNAL_INT)); - scm_c_define ("weechat:WEECHAT_HOOK_SIGNAL_POINTER", scm_from_locale_string (WEECHAT_HOOK_SIGNAL_POINTER)); - - scm_c_export ("weechat:WEECHAT_RC_OK", - "weechat:WEECHAT_RC_OK_EAT", - "weechat:WEECHAT_RC_ERROR", - "weechat:WEECHAT_CONFIG_READ_OK", - "weechat:WEECHAT_CONFIG_READ_MEMORY_ERROR", - "weechat:WEECHAT_CONFIG_READ_FILE_NOT_FOUND", - "weechat:WEECHAT_CONFIG_WRITE_OK", - "weechat:WEECHAT_CONFIG_WRITE_ERROR", - "weechat:WEECHAT_CONFIG_WRITE_MEMORY_ERROR", - "weechat:WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", - "weechat:WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", - "weechat:WEECHAT_CONFIG_OPTION_SET_ERROR", - "weechat:WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", - "weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", - "weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", - "weechat:WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", - "weechat:WEECHAT_CONFIG_OPTION_UNSET_ERROR", - "weechat:WEECHAT_LIST_POS_SORT", - "weechat:WEECHAT_LIST_POS_BEGINNING", - "weechat:WEECHAT_LIST_POS_END", - "weechat:WEECHAT_HOTLIST_LOW", - "weechat:WEECHAT_HOTLIST_MESSAGE", - "weechat:WEECHAT_HOTLIST_PRIVATE", - "weechat:WEECHAT_HOTLIST_HIGHLIGHT", - "weechat:WEECHAT_HOOK_PROCESS_RUNNING", - "weechat:WEECHAT_HOOK_PROCESS_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_OK", - "weechat:WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", - "weechat:WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", - "weechat:WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", - "weechat:WEECHAT_HOOK_CONNECT_PROXY_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_MEMORY_ERROR", - "weechat:WEECHAT_HOOK_CONNECT_TIMEOUT", - "weechat:WEECHAT_HOOK_SIGNAL_STRING", - "weechat:WEECHAT_HOOK_SIGNAL_INT", - "weechat:WEECHAT_HOOK_SIGNAL_POINTER", - NULL); -} diff --git a/src/plugins/scripts/guile/weechat-guile-api.h b/src/plugins/scripts/guile/weechat-guile-api.h deleted file mode 100644 index aaad60d54..000000000 --- a/src/plugins/scripts/guile/weechat-guile-api.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_GUILE_API_H -#define __WEECHAT_GUILE_API_H 1 - -extern int weechat_guile_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_guile_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); -extern void weechat_guile_api_module_init (void *data); - -#endif /* __WEECHAT_GUILE_API_H */ diff --git a/src/plugins/scripts/guile/weechat-guile.c b/src/plugins/scripts/guile/weechat-guile.c deleted file mode 100644 index a7dae1afe..000000000 --- a/src/plugins/scripts/guile/weechat-guile.c +++ /dev/null @@ -1,912 +0,0 @@ -/* - * Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-guile.c: guile (scheme) plugin for WeeChat - */ - -#undef _ - -#include <libguile.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <libgen.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-guile.h" -#include "weechat-guile-api.h" - - -WEECHAT_PLUGIN_NAME(GUILE_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of scheme scripts (with Guile)")); -WEECHAT_PLUGIN_AUTHOR("Sebastien Helleu <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_guile_plugin = NULL; - -int guile_quiet; -struct t_plugin_script *guile_scripts = NULL; -struct t_plugin_script *last_guile_script = NULL; -struct t_plugin_script *guile_current_script = NULL; -struct t_plugin_script *guile_registered_script = NULL; -const char *guile_current_script_filename = NULL; -SCM guile_module_weechat; -SCM guile_port; -char *guile_stdout = NULL; - -struct t_guile_function -{ - SCM proc; - SCM args; -}; - -/* - * string used to execute action "install": - * when signal "guile_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *guile_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "guile_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *guile_action_remove_list = NULL; - - -/* - * weechat_guile_stdout_flush: flush stdout - */ - -void -weechat_guile_stdout_flush () -{ - if (guile_stdout) - { - weechat_printf (NULL, - weechat_gettext ("%s: stdout/stderr: %s%s"), - GUILE_PLUGIN_NAME, guile_stdout, ""); - free (guile_stdout); - guile_stdout = NULL; - } -} - -/* - * weechat_guile_catch: execute scheme procedure with internal catch - * and return value - */ - -SCM -weechat_guile_catch (void *procedure, void *data) -{ - SCM value; - - value = scm_internal_catch (SCM_BOOL_T, - (scm_t_catch_body)procedure, - data, - (scm_t_catch_handler) scm_handle_by_message_noexit, - NULL); - return value; -} - -/* - * weechat_guile_scm_call_1: encapsulate call to scm_call_1 (to give arguments) - */ - -SCM -weechat_guile_scm_call_1 (void *proc) -{ - struct t_guile_function *guile_function; - - guile_function = (struct t_guile_function *)proc; - - return scm_call_1 (guile_function->proc, guile_function->args); -} - -/* - * weechat_guile_exec_function: execute scheme function (with optional args) - * and return value - */ - -SCM -weechat_guile_exec_function (const char *function, SCM args) -{ - SCM func, func2, value; - struct t_guile_function guile_function; - - func = weechat_guile_catch (scm_c_lookup, (void *)function); - func2 = weechat_guile_catch (scm_variable_ref, func); - - if (args) - { - guile_function.proc = func2; - guile_function.args = args; - value = weechat_guile_catch (weechat_guile_scm_call_1, &guile_function); - } - else - { - value = weechat_guile_catch (scm_call_0, func2); - } - - return value; -} - -/* - * weechat_guile_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_guile_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - SCM *alist, pair, list; - - /* make C compiler happy */ - (void) hashtable; - - alist = (SCM *)data; - - pair = scm_cons (scm_from_locale_string (key), - scm_from_locale_string (value)); - list = scm_list_1 (pair); - - *alist = scm_append (scm_list_2 (*alist, list)); -} - -/* - * weechat_guile_hashtable_to_alist: get Guile alist with a WeeChat hashtable - */ - -SCM -weechat_guile_hashtable_to_alist (struct t_hashtable *hashtable) -{ - SCM alist; - - alist = scm_list_n (SCM_UNDEFINED); - - weechat_hashtable_map_string (hashtable, - &weechat_guile_hashtable_map_cb, - &alist); - - return alist; -} - -/* - * weechat_guile_alist_to_hashtable: get WeeChat hashtable with Guile alist - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after - * use with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_guile_alist_to_hashtable (SCM alist, int hashtable_size) -{ - struct t_hashtable *hashtable; - int length, i; - SCM pair; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - length = scm_to_int (scm_length (alist)); - for (i = 0; i < length; i++) - { - pair = scm_list_ref (alist, scm_from_int (i)); - weechat_hashtable_set (hashtable, - scm_i_string_chars (scm_list_ref (pair, - scm_from_int (0))), - scm_i_string_chars (scm_list_ref (pair, - scm_from_int (1)))); - } - - return hashtable; -} - -/* - * weechat_guile_exec: execute a Guile function - */ - -void * -weechat_guile_exec (struct t_plugin_script *script, - int ret_type, const char *function, - char *format, void **argv) -{ - struct t_plugin_script *old_guile_current_script; - SCM argv_list, rc; - void *argv2[17], *ret_value; - int i, argc, *ret_int; - - old_guile_current_script = guile_current_script; - scm_set_current_module ((SCM)(script->interpreter)); - guile_current_script = script; - - if (argv && argv[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - argv2[i] = scm_from_locale_string ((char *)argv[i]); - break; - case 'i': /* integer */ - argv2[i] = scm_from_int (*((int *)argv[i])); - break; - case 'h': /* hash */ - argv2[i] = weechat_guile_hashtable_to_alist (argv[i]); - break; - } - } - for (i = argc; i < 17; i++) - { - argv2[i] = SCM_UNDEFINED; - } - argv_list = scm_list_n (argv2[0], argv2[1], - argv2[2], argv2[3], - argv2[4], argv2[5], - argv2[6], argv2[7], - argv2[8], argv2[9], - argv2[10], argv2[11], - argv2[12], argv2[13], - argv2[14], argv2[15], - argv2[16]); - rc = weechat_guile_exec_function (function, argv_list); - } - else - { - rc = weechat_guile_exec_function (function, NULL); - } - - ret_value = NULL; - - if ((ret_type == WEECHAT_SCRIPT_EXEC_STRING) && (scm_is_string (rc))) - { - ret_value = scm_to_locale_string (rc); - } - else if ((ret_type == WEECHAT_SCRIPT_EXEC_INT) && (scm_is_integer (rc))) - { - ret_int = malloc (sizeof (*ret_int)); - if (ret_int) - *ret_int = scm_to_int (rc); - ret_value = ret_int; - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_value = weechat_guile_alist_to_hashtable (rc, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" must return " - "a valid value"), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, function); - } - - if (ret_value == NULL) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: error in function \"%s\""), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, function); - } - - if (old_guile_current_script) - scm_set_current_module ((SCM)(old_guile_current_script->interpreter)); - - guile_current_script = old_guile_current_script; - - return ret_value; -} - -/* - * weechat_guile_module_init_script: init Guile module for script - */ - -void -weechat_guile_module_init_script (void *data) -{ - SCM rc; - - weechat_guile_catch (scm_c_eval_string, "(use-modules (weechat))"); - rc = weechat_guile_catch (scm_c_primitive_load, data); - - /* error loading script? */ - if (rc == SCM_BOOL_F) - { - /* if script was registered, remove it from list */ - if (guile_current_script) - { - script_remove (weechat_guile_plugin, - &guile_scripts, &last_guile_script, - guile_current_script); - } - guile_current_script = NULL; - guile_registered_script = NULL; - } -} - -/* - * weechat_guile_load: load a Guile script - */ - -int -weechat_guile_load (const char *filename) -{ - char *filename2, *ptr_base_name, *base_name; - SCM module; - - if ((weechat_guile_plugin->debug >= 2) || !guile_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - GUILE_PLUGIN_NAME, filename); - } - - guile_current_script = NULL; - guile_registered_script = NULL; - guile_current_script_filename = filename; - - filename2 = strdup (filename); - if (!filename2) - return 0; - - ptr_base_name = basename (filename2); - base_name = strdup (ptr_base_name); - module = scm_c_define_module (base_name, - &weechat_guile_module_init_script, filename2); - free (filename2); - - if (!guile_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, filename); - return 0; - } - - weechat_guile_catch (scm_gc_protect_object, (void *)module); - - guile_current_script = guile_registered_script; - guile_current_script->interpreter = (void *)module; - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_guile_plugin, - guile_scripts, - guile_current_script, - &weechat_guile_api_buffer_input_data_cb, - &weechat_guile_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_guile_load_cb: callback for script_auto_load() function - */ - -void -weechat_guile_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_guile_load (filename); -} - -/* - * weechat_guile_unload: unload a Guile script - */ - -void -weechat_guile_unload (struct t_plugin_script *script) -{ - int *rc; - void *interpreter; - - if ((weechat_guile_plugin->debug >= 2) || !guile_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - GUILE_PLUGIN_NAME, script->name); - } - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, NULL, NULL); - if (rc) - free (rc); - } - - interpreter = script->interpreter; - - if (guile_current_script == script) - guile_current_script = (guile_current_script->prev_script) ? - guile_current_script->prev_script : guile_current_script->next_script; - - script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script, - script); - - if (interpreter) - weechat_guile_catch (scm_gc_unprotect_object, interpreter); -} - -/* - * weechat_guile_unload_name: unload a Guile script by name - */ - -void -weechat_guile_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_guile_plugin, guile_scripts, name); - if (ptr_script) - { - weechat_guile_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - GUILE_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, name); - } -} - -/* - * weechat_guile_unload_all: unload all Guile scripts - */ - -void -weechat_guile_unload_all () -{ - while (guile_scripts) - { - weechat_guile_unload (guile_scripts); - } -} - -/* - * weechat_guile_reload_name: reload a Guile script by name - */ - -void -weechat_guile_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_guile_plugin, guile_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_guile_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - GUILE_PLUGIN_NAME, name); - weechat_guile_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, name); - } -} - -/* - * weechat_guile_cmd: callback for "/guile" command - */ - -int -weechat_guile_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - SCM value; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_guile_plugin, guile_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_guile_plugin, guile_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_guile_plugin, guile_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_guile_unload_all (); - script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_guile_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_guile_plugin, guile_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_guile_plugin, guile_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Guile script */ - path_script = script_search_path (weechat_guile_plugin, - argv_eol[2]); - weechat_guile_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Guile script */ - weechat_guile_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Guile script */ - weechat_guile_unload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "eval") == 0) - { - /* eval Guile code */ - value = weechat_guile_catch (scm_c_eval_string, argv_eol[2]); - if (!SCM_EQ_P (value, SCM_UNDEFINED) - && !SCM_EQ_P (value, SCM_UNSPECIFIED)) - { - scm_display (value, guile_port); - } - weechat_guile_stdout_flush (); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), GUILE_PLUGIN_NAME, - "guile"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_completion_cb: callback for script completion - */ - -int -weechat_guile_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_guile_plugin, completion, guile_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_guile_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "guile_script") == 0) - { - return script_infolist_list_scripts (weechat_guile_plugin, - guile_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_guile_signal_debug_dump_cb: dump Guile plugin data in WeeChat log - * file - */ - -int -weechat_guile_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, GUILE_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_guile_plugin, guile_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_signal_buffer_closed_cb: callback called when a buffer is - * closed - */ - -int -weechat_guile_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (guile_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_timer_action_cb: timer for executing actions - */ - -int -weechat_guile_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &guile_action_install_list) - { - script_action_install (weechat_guile_plugin, - guile_scripts, - &weechat_guile_unload, - &weechat_guile_load, - &guile_action_install_list); - } - else if (data == &guile_action_remove_list) - { - script_action_remove (weechat_guile_plugin, - guile_scripts, - &weechat_guile_unload, - &guile_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_guile_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "guile_script_install") == 0) - { - script_action_add (&guile_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_guile_timer_action_cb, - &guile_action_install_list); - } - else if (strcmp (signal, "guile_script_remove") == 0) - { - script_action_add (&guile_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_guile_timer_action_cb, - &guile_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_guile_port_fill_input: fill input - */ - -int -weechat_guile_port_fill_input (SCM port) -{ - /* make C compiler happy */ - (void) port; - - return ' '; -} - -/* - * weechat_guile_port_write: write - */ - -void -weechat_guile_port_write (SCM port, const void *data, size_t size) -{ - char *new_stdout; - int length_stdout; - - /* make C compiler happy */ - (void) port; - - /* concatenate str to guile_stdout */ - if (guile_stdout) - { - length_stdout = strlen (guile_stdout); - new_stdout = realloc (guile_stdout, length_stdout + size + 1); - if (!new_stdout) - { - free (guile_stdout); - return; - } - guile_stdout = new_stdout; - memcpy (guile_stdout + length_stdout, data, size); - guile_stdout[length_stdout + size] = '\0'; - } - else - { - guile_stdout = malloc (size + 1); - if (guile_stdout) - { - memcpy (guile_stdout, data, size); - guile_stdout[size] = '\0'; - } - } - - /* flush stdout if at least "\n" is in string */ - if (guile_stdout && (strchr (guile_stdout, '\n'))) - weechat_guile_stdout_flush (); -} - -/* - * weechat_plugin_init: initialize Guile plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; - - weechat_guile_plugin = plugin; - - guile_stdout = NULL; - - scm_init_guile (); - - guile_module_weechat = scm_c_define_module ("weechat", - &weechat_guile_api_module_init, - NULL); - scm_c_use_module ("weechat"); - weechat_guile_catch (scm_gc_protect_object, (void *)guile_module_weechat); - - init.callback_command = &weechat_guile_command_cb; - init.callback_completion = &weechat_guile_completion_cb; - init.callback_infolist = &weechat_guile_infolist_cb; - init.callback_signal_debug_dump = &weechat_guile_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_guile_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_guile_signal_script_action_cb; - init.callback_load_file = &weechat_guile_load_cb; - - guile_quiet = 1; - script_init (weechat_guile_plugin, argc, argv, &init); - guile_quiet = 0; - - script_display_short_list (weechat_guile_plugin, - guile_scripts); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: shutdown Guile interface - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - guile_quiet = 1; - script_end (plugin, &guile_scripts, &weechat_guile_unload_all); - guile_quiet = 0; - - /* unprotect module */ - weechat_guile_catch (scm_gc_unprotect_object, (void *)guile_module_weechat); - - /* free some data */ - if (guile_action_install_list) - free (guile_action_install_list); - if (guile_action_remove_list) - free (guile_action_remove_list); - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/guile/weechat-guile.h b/src/plugins/scripts/guile/weechat-guile.h deleted file mode 100644 index b868a4c10..000000000 --- a/src/plugins/scripts/guile/weechat-guile.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2011-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_GUILE_H -#define __WEECHAT_GUILE_H 1 - -#define weechat_plugin weechat_guile_plugin -#define GUILE_PLUGIN_NAME "guile" - -#define GUILE_CURRENT_SCRIPT_NAME ((guile_current_script) ? guile_current_script->name : "-") - -extern struct t_weechat_plugin *weechat_guile_plugin; - -extern int guile_quiet; -extern struct t_plugin_script *guile_scripts; -extern struct t_plugin_script *last_guile_script; -extern struct t_plugin_script *guile_current_script; -extern struct t_plugin_script *guile_registered_script; -extern const char *guile_current_script_filename; -extern SCM guile_port; - -extern SCM weechat_guile_hashtable_to_alist (struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_guile_alist_to_hashtable (SCM dict, - int hashtable_size); -extern void *weechat_guile_exec (struct t_plugin_script *script, - int ret_type, const char *function, - char *format, void **argv); -extern int weechat_guile_port_fill_input (SCM port); -extern void weechat_guile_port_write (SCM port, const void *data, size_t size); - -#endif /* __WEECHAT_GUILE_H */ diff --git a/src/plugins/scripts/lua/CMakeLists.txt b/src/plugins/scripts/lua/CMakeLists.txt deleted file mode 100644 index 7981a8ba0..000000000 --- a/src/plugins/scripts/lua/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> -# Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(lua MODULE weechat-lua.c weechat-lua.h weechat-lua-api.c -weechat-lua-api.h) - -SET_TARGET_PROPERTIES(lua PROPERTIES PREFIX "") - -IF(LUA_FOUND) - INCLUDE_DIRECTORIES(${LUA_INCLUDE_PATH} ) - IF(LUA_LIBRARY AND LUALIB_LIBRARY) - TARGET_LINK_LIBRARIES(lua ${LUA_LIBRARY} ${LUALIB_LIBRARY} weechat_scripts) - ELSE(LUA_LIBRARY AND LUALIB_LIBRARY) - TARGET_LINK_LIBRARIES(lua ${LUA_LIBRARY} weechat_scripts) - ENDIF(LUA_LIBRARY AND LUALIB_LIBRARY) -ENDIF(LUA_FOUND) - -INSTALL(TARGETS lua LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/lua/Makefile.am b/src/plugins/scripts/lua/Makefile.am deleted file mode 100644 index 336c2c33f..000000000 --- a/src/plugins/scripts/lua/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> -# Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(LUA_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = lua.la - -lua_la_SOURCES = weechat-lua.c \ - weechat-lua.h \ - weechat-lua-api.c \ - weechat-lua-api.h -lua_la_LDFLAGS = -module -lua_la_LIBADD = ../lib_weechat_plugins_scripts.la $(LUA_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c deleted file mode 100644 index 036de514c..000000000 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ /dev/null @@ -1,6474 +0,0 @@ -/* - * Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> - * Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-lua-api.c: lua API functions - */ - -#undef _ - -#include <lua.h> -#include <lualib.h> -#include <lauxlib.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-lua.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *lua_function_name = __name; \ - (void) L; \ - if (__init \ - && (!lua_current_script || !lua_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, \ - lua_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, \ - lua_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_lua_plugin, LUA_CURRENT_SCRIPT_NAME, \ - lua_function_name, __string) -#define API_RETURN_OK return 1 -#define API_RETURN_ERROR return 0 -#define API_RETURN_EMPTY \ - lua_pushstring (lua_current_interpreter, ""); \ - return 0 -#define API_RETURN_STRING(__string) \ - lua_pushstring (lua_current_interpreter, \ - (__string) ? __string : ""); \ - return 1; -#define API_RETURN_STRING_FREE(__string) \ - lua_pushstring (lua_current_interpreter, \ - (__string) ? __string : ""); \ - if (__string) \ - free (__string); \ - return 1; -#define API_RETURN_INT(__int) \ - lua_pushnumber (lua_current_interpreter, __int); \ - return 1; -#define API_RETURN_LONG(__long) \ - lua_pushnumber (lua_current_interpreter, __long); \ - return 1; - -#define API_DEF_FUNC(__name) \ - { #__name, &weechat_lua_api_##__name } - - -/* - * weechat_lua_api_register: startup function for all WeeChat Lua scripts - */ - -static int -weechat_lua_api_register (lua_State *L) -{ - const char *name, *author, *version, *license, *description; - const char *shutdown_func, *charset; - - API_FUNC(0, "register", API_RETURN_ERROR); - if (lua_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, - lua_registered_script->name); - API_RETURN_ERROR; - } - lua_current_script = NULL; - lua_registered_script = NULL; - if (lua_gettop (lua_current_interpreter) < 7) - API_WRONG_ARGS(API_RETURN_ERROR); - - name = lua_tostring (lua_current_interpreter, -7); - author = lua_tostring (lua_current_interpreter, -6); - version = lua_tostring (lua_current_interpreter, -5); - license = lua_tostring (lua_current_interpreter, -4); - description = lua_tostring (lua_current_interpreter, -3); - shutdown_func = lua_tostring (lua_current_interpreter, -2); - charset = lua_tostring (lua_current_interpreter, -1); - - if (script_search (weechat_lua_plugin, lua_scripts, name)) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, name); - API_RETURN_ERROR; - } - - /* register script */ - lua_current_script = script_add (weechat_lua_plugin, - &lua_scripts, &last_lua_script, - (lua_current_script_filename) ? - lua_current_script_filename : "", - name, - author, - version, - license, - description, - shutdown_func, - charset); - if (lua_current_script) - { - lua_registered_script = lua_current_script; - if ((weechat_lua_plugin->debug >= 2) || !lua_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - LUA_PLUGIN_NAME, name, version, description); - } - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat_lua_api_plugin_get_name: get name of plugin (return "core" for - * WeeChat core) - */ - -static int -weechat_lua_api_plugin_get_name (lua_State *L) -{ - const char *plugin, *result; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - plugin = lua_tostring (lua_current_interpreter, -1); - - result = weechat_plugin_get_name (API_STR2PTR(plugin)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_charset_set: set script charset - */ - -static int -weechat_lua_api_charset_set (lua_State *L) -{ - const char *charset; - - API_FUNC(1, "charset_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - charset = lua_tostring (lua_current_interpreter, -1); - - script_api_charset_set (lua_current_script, - charset); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_iconv_to_internal: convert string to internal WeeChat charset - */ - -static int -weechat_lua_api_iconv_to_internal (lua_State *L) -{ - const char *charset, *string; - char *result; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = lua_tostring (lua_current_interpreter, -2); - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_iconv_to_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_iconv_from_internal: convert string from WeeChat internal - * charset to another one - */ - -static int -weechat_lua_api_iconv_from_internal (lua_State *L) -{ - const char *charset, *string; - char *result; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = lua_tostring (lua_current_interpreter, -2); - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_iconv_from_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_gettext: get translated string - */ - -static int -weechat_lua_api_gettext (lua_State *L) -{ - const char *string, *result; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_gettext (string); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_ngettext: get translated string with plural form - */ - -static int -weechat_lua_api_ngettext (lua_State *L) -{ - const char *single, *plural, *result; - int count; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - single = lua_tostring (lua_current_interpreter, -3); - plural = lua_tostring (lua_current_interpreter, -2); - count = lua_tonumber (lua_current_interpreter, -1); - - result = weechat_ngettext (single, plural, count); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other "*" - * are allowed inside mask - */ - -static int -weechat_lua_api_string_match (lua_State *L) -{ - const char *string, *mask; - int case_sensitive, value; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = lua_tostring (lua_current_interpreter, -3); - mask = lua_tostring (lua_current_interpreter, -2); - case_sensitive = lua_tonumber (lua_current_interpreter, -1); - - value = weechat_string_match (string, mask, case_sensitive); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_string_has_highlight: return 1 if string contains a - * highlight (using list of words to - * highlight) - * return 0 if no highlight is found in - * string - */ - -static int -weechat_lua_api_string_has_highlight (lua_State *L) -{ - const char *string, *highlight_words; - int value; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = lua_tostring (lua_current_interpreter, -2); - highlight_words = lua_tostring (lua_current_interpreter, -1); - - value = weechat_string_has_highlight (string, highlight_words); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_string_has_highlight_regex: return 1 if string contains a - * highlight (using regular - * expression) - * return 0 if no highlight is - * found in string - */ - -static int -weechat_lua_api_string_has_highlight_regex (lua_State *L) -{ - const char *string, *regex; - int value; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = lua_tostring (lua_current_interpreter, -2); - regex = lua_tostring (lua_current_interpreter, -1); - - value = weechat_string_has_highlight_regex (string, regex); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_string_mask_to_regex: convert a mask (string with only - * "*" as wildcard) to a regex, paying - * attention to special chars in a - * regex - */ - -static int -weechat_lua_api_string_mask_to_regex (lua_State *L) -{ - const char *mask; - char *result; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - mask = lua_tostring (lua_current_interpreter, -1); - - result = weechat_string_mask_to_regex (mask); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_string_remove_color: remove WeeChat color codes from string - */ - -static int -weechat_lua_api_string_remove_color (lua_State *L) -{ - const char *string, *replacement; - char *result; - - API_FUNC(1, "string_remove_color", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - string = lua_tostring (lua_current_interpreter, -2); - replacement = lua_tostring (lua_current_interpreter, -1); - - result = weechat_string_remove_color (string, replacement); - - API_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 value; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = lua_tostring (lua_current_interpreter, -1); - - value = weechat_string_is_command_char (string); - - API_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; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_string_input_for_buffer (string); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_mkdir_home: create a directory in WeeChat home - */ - -static int -weechat_lua_api_mkdir_home (lua_State *L) -{ - const char *directory; - int mode; - - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - directory = lua_tostring (lua_current_interpreter, -2); - mode = lua_tonumber (lua_current_interpreter, -1); - - if (weechat_mkdir_home (directory, mode)) - API_RETURN_OK; - - API_RETURN_OK; -} - -/* - * weechat_lua_api_mkdir: create a directory - */ - -static int -weechat_lua_api_mkdir (lua_State *L) -{ - const char *directory; - int mode; - - API_FUNC(1, "mkdir", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - directory = lua_tostring (lua_current_interpreter, -2); - mode = lua_tonumber (lua_current_interpreter, -1); - - if (weechat_mkdir (directory, mode)) - API_RETURN_OK; - - API_RETURN_OK; -} - -/* - * weechat_lua_api_mkdir_parents: create a directory and make parent - * directories as needed - */ - -static int -weechat_lua_api_mkdir_parents (lua_State *L) -{ - const char *directory; - int mode; - - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - directory = lua_tostring (lua_current_interpreter, -2); - mode = lua_tonumber (lua_current_interpreter, -1); - - if (weechat_mkdir_parents (directory, mode)) - API_RETURN_OK; - - API_RETURN_OK; -} - -/* - * weechat_lua_api_list_new: create a new list - */ - -static int -weechat_lua_api_list_new (lua_State *L) -{ - char *result; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_add: add a string to list - */ - -static int -weechat_lua_api_list_add (lua_State *L) -{ - const char *weelist, *data, *where, *user_data; - char *result; - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = lua_tostring (lua_current_interpreter, -4); - data = lua_tostring (lua_current_interpreter, -3); - where = lua_tostring (lua_current_interpreter, -2); - user_data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(weelist), - data, - where, - API_STR2PTR(user_data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_search: search a string in list - */ - -static int -weechat_lua_api_list_search (lua_State *L) -{ - const char *weelist, *data; - char *result; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_search_pos: search position of a string in list - */ - -static int -weechat_lua_api_list_search_pos (lua_State *L) -{ - const char *weelist, *data; - int pos; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - pos = weechat_list_search_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_lua_api_list_casesearch: search a string in list (ignore case) - */ - -static int -weechat_lua_api_list_casesearch (lua_State *L) -{ - const char *weelist, *data; - char *result; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -static int -weechat_lua_api_list_casesearch_pos (lua_State *L) -{ - const char *weelist, *data; - int pos; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - pos = weechat_list_casesearch_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_lua_api_list_get: get item by position - */ - -static int -weechat_lua_api_list_get (lua_State *L) -{ - const char *weelist; - char *result; - int position; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = lua_tostring (lua_current_interpreter, -2); - position = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(weelist), - position)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_set: set new value for item - */ - -static int -weechat_lua_api_list_set (lua_State *L) -{ - const char *item, *new_value; - - API_FUNC(1, "list_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - item = lua_tostring (lua_current_interpreter, -2); - new_value = lua_tostring (lua_current_interpreter, -1); - - weechat_list_set (API_STR2PTR(item), - new_value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_list_next: get next item - */ - -static int -weechat_lua_api_list_next (lua_State *L) -{ - const char *item; - char *result; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - item = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(item))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_prev: get previous item - */ - -static int -weechat_lua_api_list_prev (lua_State *L) -{ - const char *item; - char *result; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - item = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(item))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_list_string: get string value of item - */ - -static int -weechat_lua_api_list_string (lua_State *L) -{ - const char *item, *result; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - item = lua_tostring (lua_current_interpreter, -1); - - result = weechat_list_string (API_STR2PTR(item)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_list_size: get number of elements in list - */ - -static int -weechat_lua_api_list_size (lua_State *L) -{ - const char *weelist; - int size; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - weelist = lua_tostring (lua_current_interpreter, -1); - - size = weechat_list_size (API_STR2PTR(weelist)); - - API_RETURN_INT(size); -} - -/* - * weechat_lua_api_list_remove: remove item from list - */ - -static int -weechat_lua_api_list_remove (lua_State *L) -{ - const char *weelist, *item; - - API_FUNC(1, "list_remove", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weelist = lua_tostring (lua_current_interpreter, -2); - item = lua_tostring (lua_current_interpreter, -1); - - weechat_list_remove (API_STR2PTR(weelist), - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_list_remove_all: remove all items from list - */ - -static int -weechat_lua_api_list_remove_all (lua_State *L) -{ - const char *weelist; - - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weelist = lua_tostring (lua_current_interpreter, -1); - - weechat_list_remove_all (API_STR2PTR(weelist)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_list_free: free list - */ - -static int -weechat_lua_api_list_free (lua_State *L) -{ - const char *weelist; - - API_FUNC(1, "list_free", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weelist = lua_tostring (lua_current_interpreter, -1); - - weechat_list_free (API_STR2PTR(weelist)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_reload_cb: callback for ccnfig reload - */ - -int -weechat_lua_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat_lua_api_config_new: create a new configuration file - */ - -static int -weechat_lua_api_config_new (lua_State *L) -{ - const char *name, *function, *data; - char *result; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_config_new (weechat_lua_plugin, - lua_current_script, - name, - &weechat_lua_api_config_reload_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_read_cb: callback for reading option in section - */ - -int -weechat_lua_api_config_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_lua_api_config_section_write_cb: callback for writing section - */ - -int -weechat_lua_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_lua_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_lua_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_lua_api_config_section_create_option_cb: callback to create an option - */ - -int -weechat_lua_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_lua_api_config_section_delete_option_cb: callback to delete an option - */ - -int -weechat_lua_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat_lua_api_config_new_section: create a new section in configuration file - */ - -static int -weechat_lua_api_config_new_section (lua_State *L) -{ - const char *config_file, *name, *function_read, *data_read; - const char *function_write, *data_write, *function_write_default; - const char *data_write_default, *function_create_option; - const char *data_create_option, *function_delete_option; - const char *data_delete_option; - char *result; - int user_can_add_options, user_can_delete_options; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 14) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = lua_tostring (lua_current_interpreter, -14); - name = lua_tostring (lua_current_interpreter, -13); - user_can_add_options = lua_tonumber (lua_current_interpreter, -12); - user_can_delete_options = lua_tonumber (lua_current_interpreter, -11); - function_read = lua_tostring (lua_current_interpreter, -10); - data_read = lua_tostring (lua_current_interpreter, -9); - function_write = lua_tostring (lua_current_interpreter, -8); - data_write = lua_tostring (lua_current_interpreter, -7); - function_write_default = lua_tostring (lua_current_interpreter, -6); - data_write_default = lua_tostring (lua_current_interpreter, -5); - function_create_option = lua_tostring (lua_current_interpreter, -4); - data_create_option = lua_tostring (lua_current_interpreter, -3); - function_delete_option = lua_tostring (lua_current_interpreter, -2); - data_delete_option = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_config_new_section (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(config_file), - name, - user_can_add_options, - user_can_delete_options, - &weechat_lua_api_config_read_cb, - function_read, - data_read, - &weechat_lua_api_config_section_write_cb, - function_write, - data_write, - &weechat_lua_api_config_section_write_default_cb, - function_write_default, - data_write_default, - &weechat_lua_api_config_section_create_option_cb, - function_create_option, - data_create_option, - &weechat_lua_api_config_section_delete_option_cb, - function_delete_option, - data_delete_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_search_section: search a section in configuration file - */ - -static int -weechat_lua_api_config_search_section (lua_State *L) -{ - const char *config_file, *section_name; - char *result; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = lua_tostring (lua_current_interpreter, -2); - section_name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(config_file), - section_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_option_check_value_cb: callback for checking new - * value for option - */ - -int -weechat_lua_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_lua_api_config_option_change_cb: callback for option changed - */ - -void -weechat_lua_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_lua_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_lua_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_lua_api_config_new_option: create a new option in section - */ - -static int -weechat_lua_api_config_new_option (lua_State *L) -{ - const char *config_file, *section, *name, *type, *description; - const char *string_values, *default_value, *value; - const char *function_check_value, *data_check_value, *function_change; - const char *data_change, *function_delete, *data_delete; - char *result; - int min, max, null_value_allowed; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 17) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = lua_tostring (lua_current_interpreter, -17); - section = lua_tostring (lua_current_interpreter, -16); - name = lua_tostring (lua_current_interpreter, -15); - type = lua_tostring (lua_current_interpreter, -14); - description = lua_tostring (lua_current_interpreter, -13); - string_values = lua_tostring (lua_current_interpreter, -12); - min = lua_tonumber (lua_current_interpreter, -11); - max = lua_tonumber (lua_current_interpreter, -10); - default_value = lua_tostring (lua_current_interpreter, -9); - value = lua_tostring (lua_current_interpreter, -8); - null_value_allowed = lua_tonumber (lua_current_interpreter, -7); - function_check_value = lua_tostring (lua_current_interpreter, -6); - data_check_value = lua_tostring (lua_current_interpreter, -5); - function_change = lua_tostring (lua_current_interpreter, -4); - data_change = lua_tostring (lua_current_interpreter, -3); - function_delete = lua_tostring (lua_current_interpreter, -2); - data_delete = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_config_new_option (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(config_file), - API_STR2PTR(section), - name, - type, - description, - string_values, - min, - max, - default_value, - value, - null_value_allowed, - &weechat_lua_api_config_option_check_value_cb, - function_check_value, - data_check_value, - &weechat_lua_api_config_option_change_cb, - function_change, - data_change, - &weechat_lua_api_config_option_delete_cb, - function_delete, - data_delete)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_search_option: search option in configuration file or section - */ - -static int -weechat_lua_api_config_search_option (lua_State *L) -{ - const char *config_file, *section, *option_name; - char *result; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = lua_tostring (lua_current_interpreter, -3); - section = lua_tostring (lua_current_interpreter, -2); - option_name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(config_file), - API_STR2PTR(section), - option_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_string_to_boolean: return boolean value of a string - */ - -static int -weechat_lua_api_config_string_to_boolean (lua_State *L) -{ - const char *text; - int value; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - text = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_string_to_boolean (text); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_option_reset: reset option with default value - */ - -static int -weechat_lua_api_config_option_reset (lua_State *L) -{ - const char *option; - int run_callback, rc; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -2); - run_callback = lua_tonumber (lua_current_interpreter, -1); - - rc = weechat_config_option_reset (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_option_set: set new value for option - */ - -static int -weechat_lua_api_config_option_set (lua_State *L) -{ - const char *option, *new_value; - int run_callback, rc; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = lua_tostring (lua_current_interpreter, -3); - new_value = lua_tostring (lua_current_interpreter, -2); - run_callback = lua_tonumber (lua_current_interpreter, -1); - - rc = weechat_config_option_set (API_STR2PTR(option), - new_value, - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_option_set_null: set null (undefined) value for - * option - */ - -static int -weechat_lua_api_config_option_set_null (lua_State *L) -{ - const char *option; - int run_callback, rc; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = lua_tostring (lua_current_interpreter, -2); - run_callback = lua_tonumber (lua_current_interpreter, -1); - - rc = weechat_config_option_set_null (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_option_unset: unset an option - */ - -static int -weechat_lua_api_config_option_unset (lua_State *L) -{ - const char *option; - int rc; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = lua_tostring (lua_current_interpreter, -1); - - rc = weechat_config_option_unset (API_STR2PTR(option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_option_rename: rename an option - */ - -static int -weechat_lua_api_config_option_rename (lua_State *L) -{ - const char *option, *new_name; - - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = lua_tostring (lua_current_interpreter, -2); - new_name = lua_tostring (lua_current_interpreter, -1); - - weechat_config_option_rename (API_STR2PTR(option), - new_name); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_option_is_null: return 1 if value of option is null - */ - -static int -weechat_lua_api_config_option_is_null (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(1)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_option_is_null (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_option_default_is_null: return 1 if default value of - * option is null - */ - -static int -weechat_lua_api_config_option_default_is_null (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(1)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_option_default_is_null (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_boolean: return boolean value of option - */ - -static int -weechat_lua_api_config_boolean (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_boolean (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_boolean_default: return default boolean value of option - */ - -static int -weechat_lua_api_config_boolean_default (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_boolean_default (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_integer: return integer value of option - */ - -static int -weechat_lua_api_config_integer (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_integer (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_integer_default: return default integer value of option - */ - -static int -weechat_lua_api_config_integer_default (lua_State *L) -{ - const char *option; - int value; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - value = weechat_config_integer_default (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_config_string: return string value of option - */ - -static int -weechat_lua_api_config_string (lua_State *L) -{ - const char *option, *result; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - result = weechat_config_string (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_config_string_default: return default string value of option - */ - -static int -weechat_lua_api_config_string_default (lua_State *L) -{ - const char *option, *result; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - result = weechat_config_string_default (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_config_color: return color value of option - */ - -static int -weechat_lua_api_config_color (lua_State *L) -{ - const char *option, *result; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - result = weechat_config_color (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_config_color_default: return default color value of option - */ - -static int -weechat_lua_api_config_color_default (lua_State *L) -{ - const char *option, *result; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - result = weechat_config_color_default (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_config_write_option: write an option in configuration file - */ - -static int -weechat_lua_api_config_write_option (lua_State *L) -{ - const char *config_file, *option; - - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = lua_tostring (lua_current_interpreter, -2); - option = lua_tostring (lua_current_interpreter, -1); - - weechat_config_write_option (API_STR2PTR(config_file), - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_write_line: write a line in configuration file - */ - -static int -weechat_lua_api_config_write_line (lua_State *L) -{ - const char *config_file, *option_name, *value; - - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = lua_tostring (lua_current_interpreter, -3); - option_name = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - weechat_config_write_line (API_STR2PTR(config_file), - option_name, - "%s", - value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_write: write configuration file - */ - -static int -weechat_lua_api_config_write (lua_State *L) -{ - const char *config_file; - int rc; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - config_file = lua_tostring (lua_current_interpreter, -1); - - rc = weechat_config_write (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_read: read configuration file - */ - -static int -weechat_lua_api_config_read (lua_State *L) -{ - const char *config_file; - int rc; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - config_file = lua_tostring (lua_current_interpreter, -1); - - rc = weechat_config_read (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_reload: reload configuration file - */ - -static int -weechat_lua_api_config_reload (lua_State *L) -{ - const char *config_file; - int rc; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - config_file = lua_tostring (lua_current_interpreter, -1); - - rc = weechat_config_reload (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_option_free: free an option in configuration file - */ - -static int -weechat_lua_api_config_option_free (lua_State *L) -{ - const char *option; - - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = lua_tostring (lua_current_interpreter, -1); - - script_api_config_option_free (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_section_free_options: free all options of a section - * in configuration file - */ - -static int -weechat_lua_api_config_section_free_options (lua_State *L) -{ - const char *section; - - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - section = lua_tostring (lua_current_interpreter, -1); - - script_api_config_section_free_options (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(section)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_section_free: free section in configuration file - */ - -static int -weechat_lua_api_config_section_free (lua_State *L) -{ - const char *section; - - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - section = lua_tostring (lua_current_interpreter, -1); - - script_api_config_section_free (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(section)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_free: free configuration file - */ - -static int -weechat_lua_api_config_free (lua_State *L) -{ - const char *config_file; - - API_FUNC(1, "config_free", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = lua_tostring (lua_current_interpreter, -1); - - script_api_config_free (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(config_file)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_get: get config option - */ - -static int -weechat_lua_api_config_get (lua_State *L) -{ - const char *option; - char *result; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - option = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_config_get (option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_config_get_plugin: get value of a plugin option - */ - -static int -weechat_lua_api_config_get_plugin (lua_State *L) -{ - const char *option, *result; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - option = lua_tostring (lua_current_interpreter, -1); - - result = script_api_config_get_plugin (weechat_lua_plugin, - lua_current_script, - option); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_config_is_set_plugin: check if a plugin option is set - */ - -static int -weechat_lua_api_config_is_set_plugin (lua_State *L) -{ - const char *option; - int rc; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = lua_tostring (lua_current_interpreter, -1); - - rc = script_api_config_is_set_plugin (weechat_lua_plugin, - lua_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_set_plugin: set value of a plugin option - */ - -static int -weechat_lua_api_config_set_plugin (lua_State *L) -{ - const char *option, *value; - int rc; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - rc = script_api_config_set_plugin (weechat_lua_plugin, - lua_current_script, - option, - value); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_config_set_desc_plugin: set description of a plugin option - */ - -static int -weechat_lua_api_config_set_desc_plugin (lua_State *L) -{ - const char *option, *description; - - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = lua_tostring (lua_current_interpreter, -2); - description = lua_tostring (lua_current_interpreter, -1); - - script_api_config_set_desc_plugin (weechat_lua_plugin, - lua_current_script, - option, - description); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_config_unset_plugin: unset plugin option - */ - -static int -weechat_lua_api_config_unset_plugin (lua_State *L) -{ - const char *option; - int rc; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = lua_tostring (lua_current_interpreter, -1); - - rc = script_api_config_unset_plugin (weechat_lua_plugin, - lua_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_key_bind: bind key(s) - */ - -static int -weechat_lua_api_key_bind (lua_State *L) -{ - const char *context; - struct t_hashtable *hashtable; - int num_keys; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = lua_tostring (lua_current_interpreter, -2); - hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (context, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_lua_api_key_unbind: unbind key(s) - */ - -static int -weechat_lua_api_key_unbind (lua_State *L) -{ - const char *context, *key; - int num_keys; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = lua_tostring (lua_current_interpreter, -2); - key = lua_tostring (lua_current_interpreter, -1); - - num_keys = weechat_key_unbind (context, key); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_lua_api_prefix: get a prefix, used for display - */ - -static int -weechat_lua_api_prefix (lua_State *L) -{ - const char *prefix, *result; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - prefix = lua_tostring (lua_current_interpreter, -1); - - result = weechat_prefix (prefix); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_color: get a color code, used for display - */ - -static int -weechat_lua_api_color (lua_State *L) -{ - const char *color, *result; - - API_FUNC(0, "color", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - color = lua_tostring (lua_current_interpreter, -1); - - result = weechat_color (color); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_print: print message in a buffer - */ - -static int -weechat_lua_api_print (lua_State *L) -{ - const char *buffer, *message; - - API_FUNC(0, "print", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -2); - message = lua_tostring (lua_current_interpreter, -1); - - script_api_printf (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer), - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_print_date_tags: print message in a buffer with optional - * date and tags - */ - -static int -weechat_lua_api_print_date_tags (lua_State *L) -{ - const char *buffer, *tags, *message; - int date; - - API_FUNC(1, "print_date_tags", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -4); - date = lua_tonumber (lua_current_interpreter, -3); - tags = lua_tostring (lua_current_interpreter, -2); - message = lua_tostring (lua_current_interpreter, -1); - - script_api_printf_date_tags (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer), - date, - tags, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_print_y: print message in a buffer with free content - */ - -static int -weechat_lua_api_print_y (lua_State *L) -{ - const char *buffer, *message; - int y; - - API_FUNC(1, "print_y", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -3); - y = lua_tonumber (lua_current_interpreter, -2); - message = lua_tostring (lua_current_interpreter, -1); - - script_api_printf_y (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer), - y, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_log_print: print message in WeeChat log file - */ - -static int -weechat_lua_api_log_print (lua_State *L) -{ - const char *message; - - API_FUNC(1, "log_print", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - message = lua_tostring (lua_current_interpreter, -1); - - script_api_log_printf (weechat_lua_plugin, - lua_current_script, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_hook_command_cb: callback for command hooked - */ - -int -weechat_lua_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_command: hook a command - */ - -static int -weechat_lua_api_hook_command (lua_State *L) -{ - const char *command, *description, *args, *args_description, *completion; - const char *function, *data; - char *result; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = lua_tostring (lua_current_interpreter, -7); - description = lua_tostring (lua_current_interpreter, -6); - args = lua_tostring (lua_current_interpreter, -5); - args_description = lua_tostring (lua_current_interpreter, -4); - completion = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_command (weechat_lua_plugin, - lua_current_script, - command, - description, - args, - args_description, - completion, - &weechat_lua_api_hook_command_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_lua_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_command_run: hook a command_run - */ - -static int -weechat_lua_api_hook_command_run (lua_State *L) -{ - const char *command, *function, *data; - char *result; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_command_run (weechat_lua_plugin, - lua_current_script, - command, - &weechat_lua_api_hook_command_run_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_lua_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_timer: hook a timer - */ - -static int -weechat_lua_api_hook_timer (lua_State *L) -{ - int interval, align_second, max_calls; - const char *function, *data; - char *result; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - interval = lua_tonumber (lua_current_interpreter, -5); - align_second = lua_tonumber (lua_current_interpreter, -4); - max_calls = lua_tonumber (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_timer (weechat_lua_plugin, - lua_current_script, - interval, - align_second, - max_calls, - &weechat_lua_api_hook_timer_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_lua_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_fd: hook a fd - */ - -static int -weechat_lua_api_hook_fd (lua_State *L) -{ - int fd, read, write, exception; - const char *function, *data; - char *result; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - fd = lua_tonumber (lua_current_interpreter, -6); - read = lua_tonumber (lua_current_interpreter, -5); - write = lua_tonumber (lua_current_interpreter, -4); - exception = lua_tonumber (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_fd (weechat_lua_plugin, - lua_current_script, - fd, - read, - write, - exception, - &weechat_lua_api_hook_fd_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_process_cb: callback for process hooked - */ - -int -weechat_lua_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = &return_code; - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssiss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_process: hook a process - */ - -static int -weechat_lua_api_hook_process (lua_State *L) -{ - const char *command, *function, *data; - int timeout; - char *result; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = lua_tostring (lua_current_interpreter, -4); - timeout = lua_tonumber (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_process (weechat_lua_plugin, - lua_current_script, - command, - timeout, - &weechat_lua_api_hook_process_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_process_hashtable: hook a process with options in - * a hashtable - */ - -static int -weechat_lua_api_hook_process_hashtable (lua_State *L) -{ - const char *command, *function, *data; - struct t_hashtable *options; - int timeout; - char *result; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = lua_tostring (lua_current_interpreter, -5); - options = weechat_lua_tohashtable (lua_current_interpreter, -4, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - timeout = lua_tonumber (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_lua_plugin, - lua_current_script, - command, - options, - timeout, - &weechat_lua_api_hook_process_cb, - function, - data)); - - if (options) - weechat_hashtable_free (options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_lua_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_connect: hook a connection - */ - -static int -weechat_lua_api_hook_connect (lua_State *L) -{ - const char *proxy, *address, *local_hostname, *function, *data; - int port, sock, ipv6; - char *result; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 8) - API_WRONG_ARGS(API_RETURN_EMPTY); - - proxy = lua_tostring (lua_current_interpreter, -8); - address = lua_tostring (lua_current_interpreter, -7); - port = lua_tonumber (lua_current_interpreter, -6); - sock = lua_tonumber (lua_current_interpreter, -5); - ipv6 = lua_tonumber (lua_current_interpreter, -4); - local_hostname = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_connect (weechat_lua_plugin, - lua_current_script, - proxy, - address, - port, - sock, - ipv6, - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - local_hostname, - &weechat_lua_api_hook_connect_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_print_cb: callback for print hooked - */ - -int -weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_print: hook a print - */ - -static int -weechat_lua_api_hook_print (lua_State *L) -{ - const char *buffer, *tags, *message, *function, *data; - char *result; - int strip_colors; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -6); - tags = lua_tostring (lua_current_interpreter, -5); - message = lua_tostring (lua_current_interpreter, -4); - strip_colors = lua_tonumber (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_print (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer), - tags, - message, - strip_colors, - &weechat_lua_api_hook_print_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_lua_api_hook_signal_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_signal: hook a signal - */ - -static int -weechat_lua_api_hook_signal (lua_State *L) -{ - const char *signal, *function, *data; - char *result; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_signal (weechat_lua_plugin, - lua_current_script, - signal, - &weechat_lua_api_hook_signal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_signal_send: send a signal - */ - -static int -weechat_lua_api_hook_signal_send (lua_State *L) -{ - const char *signal, *type_data, *signal_data; - int number; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - signal_data = NULL; - - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = lua_tostring (lua_current_interpreter, -3); - type_data = lua_tostring (lua_current_interpreter, -2); - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - signal_data = lua_tostring (lua_current_interpreter, -1); - weechat_hook_signal_send (signal, type_data, (void *)signal_data); - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - number = lua_tonumber (lua_current_interpreter, -1); - weechat_hook_signal_send (signal, type_data, &number); - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - signal_data = lua_tostring (lua_current_interpreter, -1); - weechat_hook_signal_send (signal, type_data, - API_STR2PTR(signal_data)); - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_lua_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_lua_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = hashtable; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssh", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_hsignal: hook a hsignal - */ - -static int -weechat_lua_api_hook_hsignal (lua_State *L) -{ - const char *signal, *function, *data; - char *result; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_hsignal (weechat_lua_plugin, - lua_current_script, - signal, - &weechat_lua_api_hook_hsignal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_hsignal_send: send a hsignal - */ - -static int -weechat_lua_api_hook_hsignal_send (lua_State *L) -{ - const char *signal; - struct t_hashtable *hashtable; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = lua_tostring (lua_current_interpreter, -2); - hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (signal, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_lua_api_hook_config_cb (void *data, const char *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_config: hook a config option - */ - -static int -weechat_lua_api_hook_config (lua_State *L) -{ - const char *option, *function, *data; - char *result; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - option = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_config (weechat_lua_plugin, - lua_current_script, - option, - &weechat_lua_api_hook_config_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_lua_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_hook_completion: hook a completion - */ - -static int -weechat_lua_api_hook_completion (lua_State *L) -{ - const char *completion, *description, *function, *data; - char *result; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = lua_tostring (lua_current_interpreter, -4); - description = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_completion (weechat_lua_plugin, - lua_current_script, - completion, - description, - &weechat_lua_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_completion_list_add: add a word to list for a completion - */ - -static int -weechat_lua_api_hook_completion_list_add (lua_State *L) -{ - const char *completion, *word, *where; - int nick_completion; - - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = lua_tostring (lua_current_interpreter, -4); - word = lua_tostring (lua_current_interpreter, -3); - nick_completion = lua_tonumber (lua_current_interpreter, -2); - where = lua_tostring (lua_current_interpreter, -1); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_lua_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, - const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat_lua_api_hook_modifier: hook a modifier - */ - -static int -weechat_lua_api_hook_modifier (lua_State *L) -{ - const char *modifier, *function, *data; - char *result; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - modifier = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_modifier (weechat_lua_plugin, - lua_current_script, - modifier, - &weechat_lua_api_hook_modifier_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_modifier_exec: execute a modifier hook - */ - -static int -weechat_lua_api_hook_modifier_exec (lua_State *L) -{ - const char *modifier, *modifier_data, *string; - char *result; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - modifier = lua_tostring (lua_current_interpreter, -3); - modifier_data = lua_tostring (lua_current_interpreter, -2); - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hook_modifier_exec (modifier, modifier_data, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_lua_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat_lua_api_hook_info: hook an info - */ - -static int -weechat_lua_api_hook_info (lua_State *L) -{ - const char *info_name, *description, *args_description, *function, *data; - char *result; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = lua_tostring (lua_current_interpreter, -5); - description = lua_tostring (lua_current_interpreter, -4); - args_description = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_info (weechat_lua_plugin, - lua_current_script, - info_name, - description, - args_description, - &weechat_lua_api_hook_info_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_lua_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = hashtable; - - return (struct t_hashtable *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssh", func_argv); - } - - return NULL; -} - -/* - * weechat_lua_api_hook_info_hashtable: hook an info_hashtable - */ - -static int -weechat_lua_api_hook_info_hashtable (lua_State *L) -{ - const char *info_name, *description, *args_description; - const char *output_description, *function, *data; - char *result; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = lua_tostring (lua_current_interpreter, -6); - description = lua_tostring (lua_current_interpreter, -5); - args_description = lua_tostring (lua_current_interpreter, -4); - output_description = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_lua_plugin, - lua_current_script, - info_name, - description, - args_description, - output_description, - &weechat_lua_api_hook_info_hashtable_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_lua_api_hook_infolist_cb (void *data, const char *info_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat_lua_api_hook_infolist: hook an infolist - */ - -static int -weechat_lua_api_hook_infolist (lua_State *L) -{ - const char *infolist_name, *description, *pointer_description; - const char *args_description, *function, *data; - char *result; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist_name = lua_tostring (lua_current_interpreter, -6); - description = lua_tostring (lua_current_interpreter, -5); - pointer_description = lua_tostring (lua_current_interpreter, -4); - args_description = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_infolist (weechat_lua_plugin, - lua_current_script, - infolist_name, - description, - pointer_description, - args_description, - &weechat_lua_api_hook_infolist_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_lua_api_hook_focus_cb (void *data, - struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = info; - - return (struct t_hashtable *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sh", func_argv); - } - - return NULL; -} - -/* - * weechat_lua_api_hook_focus: hook a focus - */ - -static int -weechat_lua_api_hook_focus (lua_State *L) -{ - const char *area, *function, *data; - char *result; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - area = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_hook_focus (weechat_lua_plugin, - lua_current_script, - area, - &weechat_lua_api_hook_focus_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_unhook: unhook something - */ - -static int -weechat_lua_api_unhook (lua_State *L) -{ - const char *hook; - - API_FUNC(1, "unhook", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - hook = lua_tostring (lua_current_interpreter, -1); - - script_api_unhook (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(hook)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_unhook_all: unhook all for script - */ - -static int -weechat_lua_api_unhook_all (lua_State *L) -{ - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_lua_plugin, lua_current_script); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_lua_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_buffer_close_cb: callback for buffer closed - */ - -int -weechat_lua_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_buffer_new: create a new buffer - */ - -static int -weechat_lua_api_buffer_new (lua_State *L) -{ - const char *name, *function_input, *data_input, *function_close; - const char *data_close; - char *result; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -5); - function_input = lua_tostring (lua_current_interpreter, -4); - data_input = lua_tostring (lua_current_interpreter, -3); - function_close = lua_tostring (lua_current_interpreter, -2); - data_close = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_buffer_new (weechat_lua_plugin, - lua_current_script, - name, - &weechat_lua_api_buffer_input_data_cb, - function_input, - data_input, - &weechat_lua_api_buffer_close_cb, - function_close, - data_close)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_buffer_search: search a buffer - */ - -static int -weechat_lua_api_buffer_search (lua_State *L) -{ - const char *plugin, *name; - char *result; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - plugin = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_buffer_search (plugin, name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_buffer_search_main: search main buffer (WeeChat core buffer) - */ - -static int -weechat_lua_api_buffer_search_main (lua_State *L) -{ - char *result; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_current_buffer: get current buffer - */ - -static int -weechat_lua_api_current_buffer (lua_State *L) -{ - char *result; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_buffer_clear: clear a buffer - */ - -static int -weechat_lua_api_buffer_clear (lua_State *L) -{ - const char *buffer; - - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -1); - - weechat_buffer_clear (API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_close: close a buffer - */ - -static int -weechat_lua_api_buffer_close (lua_State *L) -{ - const char *buffer; - - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -1); - - script_api_buffer_close (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_merge: merge a buffer to another buffer - */ - -static int -weechat_lua_api_buffer_merge (lua_State *L) -{ - const char *buffer, *target_buffer; - - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -2); - target_buffer = lua_tostring (lua_current_interpreter, -1); - - weechat_buffer_merge (API_STR2PTR(buffer), - API_STR2PTR(target_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_unmerge: unmerge a buffer from a group of merged - * buffers - */ - -static int -weechat_lua_api_buffer_unmerge (lua_State *L) -{ - const char *buffer; - int number; - - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -2); - number = lua_tonumber (lua_current_interpreter, -1); - - weechat_buffer_unmerge (API_STR2PTR(buffer), number); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_get_integer: get a buffer property as integer - */ - -static int -weechat_lua_api_buffer_get_integer (lua_State *L) -{ - const char *buffer, *property; - int value; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - value = weechat_buffer_get_integer (API_STR2PTR(buffer), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_buffer_get_string: get a buffer property as string - */ - -static int -weechat_lua_api_buffer_get_string (lua_State *L) -{ - const char *buffer, *property, *result; - - API_FUNC(1, "buffer_get_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = weechat_buffer_get_string (API_STR2PTR(buffer), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_buffer_get_pointer: get a buffer property as pointer - */ - -static int -weechat_lua_api_buffer_get_pointer (lua_State *L) -{ - const char *buffer, *property; - char *result; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(buffer), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_buffer_set: set a buffer property - */ - -static int -weechat_lua_api_buffer_set (lua_State *L) -{ - const char *buffer, *property, *value; - - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -3); - property = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - weechat_buffer_set (API_STR2PTR(buffer), property, value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_buffer_string_replace_local_var: replace local variables ($var) in a string, - * using value of local variables - */ - -static int -weechat_lua_api_buffer_string_replace_local_var (lua_State *L) -{ - const char *buffer, *string; - char *result; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -2); - string = lua_tostring (lua_current_interpreter, -1); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(buffer), string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_buffer_match_list: return 1 if buffer matches list of buffers - */ - -static int -weechat_lua_api_buffer_match_list (lua_State *L) -{ - const char *buffer, *string; - int value; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - buffer = lua_tostring (lua_current_interpreter, -2); - string = lua_tostring (lua_current_interpreter, -1); - - value = weechat_buffer_match_list (API_STR2PTR(buffer), - string); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_current_window: get current window - */ - -static int -weechat_lua_api_current_window (lua_State *L) -{ - char *result; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_window_search_with_buffer: search a window with buffer - * pointer - */ - -static int -weechat_lua_api_window_search_with_buffer (lua_State *L) -{ - const char *buffer; - char *result; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(buffer))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_window_get_integer: get a window property as integer - */ - -static int -weechat_lua_api_window_get_integer (lua_State *L) -{ - const char *window, *property; - int value; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - window = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - value = weechat_window_get_integer (API_STR2PTR(window), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_window_get_string: get a window property as string - */ - -static int -weechat_lua_api_window_get_string (lua_State *L) -{ - const char *window, *property, *result; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = weechat_window_get_string (API_STR2PTR(window), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_window_get_pointer: get a window property as pointer - */ - -static int -weechat_lua_api_window_get_pointer (lua_State *L) -{ - const char *window, *property; - char *result; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(window), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_window_set_title: set window title - */ - -static int -weechat_lua_api_window_set_title (lua_State *L) -{ - const char *title; - - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - title = lua_tostring (lua_current_interpreter, -1); - - weechat_window_set_title (title); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_nicklist_add_group: add a group in nicklist - */ - -static int -weechat_lua_api_nicklist_add_group (lua_State *L) -{ - const char *buffer, *parent_group, *name, *color; - char *result; - int visible; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -5); - parent_group = lua_tostring (lua_current_interpreter, -4); - name = lua_tostring (lua_current_interpreter, -3); - color = lua_tostring (lua_current_interpreter, -2); - visible = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(buffer), - API_STR2PTR(parent_group), - name, - color, - visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_search_group: search a group in nicklist - */ - -static int -weechat_lua_api_nicklist_search_group (lua_State *L) -{ - const char *buffer, *from_group, *name; - char *result; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - from_group = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_add_nick: add a nick in nicklist - */ - -static int -weechat_lua_api_nicklist_add_nick (lua_State *L) -{ - const char *buffer, *group, *name, *color, *prefix, *prefix_color; - char *result; - int visible; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -7); - group = lua_tostring (lua_current_interpreter, -6); - name = lua_tostring (lua_current_interpreter, -5); - color = lua_tostring (lua_current_interpreter, -4); - prefix = lua_tostring (lua_current_interpreter, -3); - prefix_color = lua_tostring (lua_current_interpreter, -2); - visible = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(buffer), - API_STR2PTR(group), - name, - color, - prefix, - prefix_color, - visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_search_nick: search a nick in nicklist - */ - -static int -weechat_lua_api_nicklist_search_nick (lua_State *L) -{ - const char *buffer, *from_group, *name; - char *result; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - from_group = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_remove_group: remove a group from nicklist - */ - -static int -weechat_lua_api_nicklist_remove_group (lua_State *L) -{ - const char *buffer, *group; - - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -3); - group = lua_tostring (lua_current_interpreter, -2); - - weechat_nicklist_remove_group (API_STR2PTR(buffer), - API_STR2PTR(group)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_nicklist_remove_nick: remove a nick from nicklist - */ - -static int -weechat_lua_api_nicklist_remove_nick (lua_State *L) -{ - const char *buffer, *nick; - - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -3); - nick = lua_tostring (lua_current_interpreter, -2); - - weechat_nicklist_remove_nick (API_STR2PTR(buffer), - API_STR2PTR(nick)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_nicklist_remove_all: remove all groups/nicks from nicklist - */ - -static int -weechat_lua_api_nicklist_remove_all (lua_State *L) -{ - const char *buffer; - - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -3); - - weechat_nicklist_remove_all (API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_nicklist_group_get_integer: get a group property as integer - */ - -static int -weechat_lua_api_nicklist_group_get_integer (lua_State *L) -{ - const char *buffer, *group, *property; - int value; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = lua_tostring (lua_current_interpreter, -3); - group = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - value = weechat_nicklist_group_get_integer (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_nicklist_group_get_string: get a group property as string - */ - -static int -weechat_lua_api_nicklist_group_get_string (lua_State *L) -{ - const char *buffer, *group, *property, *result; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - group = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = weechat_nicklist_group_get_string (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_nicklist_group_get_pointer: get a group property as pointer - */ - -static int -weechat_lua_api_nicklist_group_get_pointer (lua_State *L) -{ - const char *buffer, *group, *property; - char *result; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - group = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(group), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_group_set: set a group property - */ - -static int -weechat_lua_api_nicklist_group_set (lua_State *L) -{ - const char *buffer, *group, *property, *value; - - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -4); - group = lua_tostring (lua_current_interpreter, -3); - property = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - weechat_nicklist_group_set (API_STR2PTR(buffer), - API_STR2PTR(group), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_nicklist_nick_get_integer: get a nick property as integer - */ - -static int -weechat_lua_api_nicklist_nick_get_integer (lua_State *L) -{ - const char *buffer, *nick, *property; - int value; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = lua_tostring (lua_current_interpreter, -3); - nick = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - value = weechat_nicklist_nick_get_integer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_nicklist_nick_get_string: get a nick property as string - */ - -static int -weechat_lua_api_nicklist_nick_get_string (lua_State *L) -{ - const char *buffer, *nick, *property, *result; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - nick = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_nicklist_nick_get_pointer: get a nick property as pointer - */ - -static int -weechat_lua_api_nicklist_nick_get_pointer (lua_State *L) -{ - const char *buffer, *nick, *property; - char *result; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -3); - nick = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_nicklist_nick_set: set a nick property - */ - -static int -weechat_lua_api_nicklist_nick_set (lua_State *L) -{ - const char *buffer, *nick, *property, *value; - - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = lua_tostring (lua_current_interpreter, -4); - nick = lua_tostring (lua_current_interpreter, -3); - property = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - weechat_nicklist_nick_set (API_STR2PTR(buffer), - API_STR2PTR(nick), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_bar_item_search: search a bar item - */ - -static int -weechat_lua_api_bar_item_search (lua_State *L) -{ - const char *name; - char *result; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_bar_item_search (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat_lua_api_bar_item_new: add a new bar item - */ - -static int -weechat_lua_api_bar_item_new (lua_State *L) -{ - const char *name, *function, *data; - char *result; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (script_api_bar_item_new (weechat_lua_plugin, - lua_current_script, - name, - &weechat_lua_api_bar_item_build_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_bar_item_update: update a bar item on screen - */ - -static int -weechat_lua_api_bar_item_update (lua_State *L) -{ - const char *name; - - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - name = lua_tostring (lua_current_interpreter, -1); - - weechat_bar_item_update (name); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_bar_item_remove: remove a bar item - */ - -static int -weechat_lua_api_bar_item_remove (lua_State *L) -{ - const char *item; - - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - item = lua_tostring (lua_current_interpreter, -1); - - script_api_bar_item_remove (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_bar_search: search a bar - */ - -static int -weechat_lua_api_bar_search (lua_State *L) -{ - const char *name; - char *result; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_bar_search (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_bar_new: add a new bar - */ - -static int -weechat_lua_api_bar_new (lua_State *L) -{ - const char *name, *hidden, *priority, *type, *conditions, *position; - const char *filling_top_bottom, *filling_left_right, *size, *size_max; - const char *color_fg, *color_delim, *color_bg, *separator, *items; - char *result; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 15) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -15); - hidden = lua_tostring (lua_current_interpreter, -14); - priority = lua_tostring (lua_current_interpreter, -13); - type = lua_tostring (lua_current_interpreter, -12); - conditions = lua_tostring (lua_current_interpreter, -11); - position = lua_tostring (lua_current_interpreter, -10); - filling_top_bottom = lua_tostring (lua_current_interpreter, -9); - filling_left_right = lua_tostring (lua_current_interpreter, -8); - size = lua_tostring (lua_current_interpreter, -7); - size_max = lua_tostring (lua_current_interpreter, -6); - color_fg = lua_tostring (lua_current_interpreter, -5); - color_delim = lua_tostring (lua_current_interpreter, -4); - color_bg = lua_tostring (lua_current_interpreter, -3); - separator = lua_tostring (lua_current_interpreter, -2); - items = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_bar_new (name, - hidden, - priority, - type, - conditions, - position, - filling_top_bottom, - filling_left_right, - size, - size_max, - color_fg, - color_delim, - color_bg, - separator, - items)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_bar_set: set a bar property - */ - -static int -weechat_lua_api_bar_set (lua_State *L) -{ - const char *bar, *property, *value; - - API_FUNC(1, "bar_set", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - bar = lua_tostring (lua_current_interpreter, -3); - property = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - weechat_bar_set (API_STR2PTR(bar), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_bar_update: update a bar on screen - */ - -static int -weechat_lua_api_bar_update (lua_State *L) -{ - const char *name; - - API_FUNC(1, "bar_update", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - name = lua_tostring (lua_current_interpreter, -1); - - weechat_bar_update (name); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_bar_remove: remove a bar - */ - -static int -weechat_lua_api_bar_remove (lua_State *L) -{ - const char *bar; - - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - bar = lua_tostring (lua_current_interpreter, -1); - - weechat_bar_remove (API_STR2PTR(bar)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_command: send command to server - */ - -static int -weechat_lua_api_command (lua_State *L) -{ - const char *buffer, *command; - - API_FUNC(1, "command", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = lua_tostring (lua_current_interpreter, -2); - command = lua_tostring (lua_current_interpreter, -1); - - script_api_command (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(buffer), - command); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_info_get: get info (as string) - */ - -static int -weechat_lua_api_info_get (lua_State *L) -{ - const char *info_name, *arguments, *result; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = lua_tostring (lua_current_interpreter, -2); - arguments = lua_tostring (lua_current_interpreter, -1); - - result = weechat_info_get (info_name, arguments); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_info_get_hashtable: get info (as hashtable) - */ - -static int -weechat_lua_api_info_get_hashtable (lua_State *L) -{ - const char *info_name; - struct t_hashtable *table, *result_hashtable; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = lua_tostring (lua_current_interpreter, -2); - table = weechat_lua_tohashtable (lua_current_interpreter, -1, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (info_name, table); - - weechat_lua_pushhashtable (lua_current_interpreter, result_hashtable); - - if (table) - weechat_hashtable_free (table); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - return 1; -} - -/* - * weechat_lua_api_infolist_new: create new infolist - */ - -static int -weechat_lua_api_infolist_new (lua_State *L) -{ - char *result; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_new_item: create new item in infolist - */ - -static int -weechat_lua_api_infolist_new_item (lua_State *L) -{ - const char *infolist; - char *result; - - API_FUNC(1, "infolist_new_item", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(infolist))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_new_var_integer: create new integer variable in - * infolist - */ - -static int -weechat_lua_api_infolist_new_var_integer (lua_State *L) -{ - const char *infolist, *name; - char *result; - int value; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -3); - name = lua_tostring (lua_current_interpreter, -2); - value = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_new_var_string: create new string variable in - * infolist - */ - -static int -weechat_lua_api_infolist_new_var_string (lua_State *L) -{ - const char *infolist, *name, *value; - char *result; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -3); - name = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_new_var_pointer: create new pointer variable in - * infolist - */ - -static int -weechat_lua_api_infolist_new_var_pointer (lua_State *L) -{ - const char *infolist, *name, *value; - char *result; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -3); - name = lua_tostring (lua_current_interpreter, -2); - value = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(infolist), - name, - API_STR2PTR(value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_new_var_time: create new time variable in infolist - */ - -static int -weechat_lua_api_infolist_new_var_time (lua_State *L) -{ - const char *infolist, *name; - char *result; - int value; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -3); - name = lua_tostring (lua_current_interpreter, -2); - value = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_get: get list with infos - */ - -static int -weechat_lua_api_infolist_get (lua_State *L) -{ - const char *name, *pointer, *arguments; - char *result; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - arguments = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_get (name, - API_STR2PTR(pointer), - arguments)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_next: move item pointer to next item in infolist - */ - -static int -weechat_lua_api_infolist_next (lua_State *L) -{ - const char *infolist; - int value; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - infolist = lua_tostring (lua_current_interpreter, -1); - - value = weechat_infolist_next (API_STR2PTR(infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_infolist_prev: move item pointer to previous item in infolist - */ - -static int -weechat_lua_api_infolist_prev (lua_State *L) -{ - const char *infolist; - int value; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - infolist = lua_tostring (lua_current_interpreter, -1); - - value = weechat_infolist_prev (API_STR2PTR(infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_infolist_reset_item_cursor: reset pointer to current item in - * infolist - */ - -static int -weechat_lua_api_infolist_reset_item_cursor (lua_State *L) -{ - const char *infolist; - - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - infolist = lua_tostring (lua_current_interpreter, -1); - - weechat_infolist_reset_item_cursor (API_STR2PTR(infolist)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_infolist_fields: get list of fields for current item of infolist - */ - -static int -weechat_lua_api_infolist_fields (lua_State *L) -{ - const char *infolist, *result; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -1); - - result = weechat_infolist_fields (API_STR2PTR(infolist)); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_infolist_integer: get integer value of a variable in infolist - */ - -static int -weechat_lua_api_infolist_integer (lua_State *L) -{ - const char *infolist, *variable; - int value; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - infolist = lua_tostring (lua_current_interpreter, -2); - variable = lua_tostring (lua_current_interpreter, -1); - - value = weechat_infolist_integer (API_STR2PTR(infolist), - variable); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_infolist_string: get string value of a variable in infolist - */ - -static int -weechat_lua_api_infolist_string (lua_State *L) -{ - const char *infolist, *variable, *result; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -2); - variable = lua_tostring (lua_current_interpreter, -1); - - result = weechat_infolist_string (API_STR2PTR(infolist), - variable); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_infolist_pointer: get pointer value of a variable in infolist - */ - -static int -weechat_lua_api_infolist_pointer (lua_State *L) -{ - const char *infolist, *variable; - char *result; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -2); - variable = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(infolist), - variable)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_time: get time value of a variable in infolist - */ - -static int -weechat_lua_api_infolist_time (lua_State *L) -{ - const char *infolist, *variable; - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = lua_tostring (lua_current_interpreter, -2); - variable = lua_tostring (lua_current_interpreter, -1); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(infolist), - variable); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_infolist_free: free infolist - */ - -static int -weechat_lua_api_infolist_free (lua_State *L) -{ - const char *infolist; - - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - infolist = lua_tostring (lua_current_interpreter, -1); - - weechat_infolist_free (API_STR2PTR(infolist)); - - API_RETURN_OK; -} - -/* - * weechat_lua_api_hdata_get: get hdata - */ - -static int -weechat_lua_api_hdata_get (lua_State *L) -{ - const char *name; - char *result; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_hdata_get (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hdata_get_var_offset: get offset of variable in hdata - */ - -static int -weechat_lua_api_hdata_get_var_offset (lua_State *L) -{ - const char *hdata, *name; - int value; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - value = weechat_hdata_get_var_offset (API_STR2PTR(hdata), name); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_hdata_get_var_type_string: get type of variable as string in - * hdata - */ - -static int -weechat_lua_api_hdata_get_var_type_string (lua_State *L) -{ - const char *hdata, *name, *result; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_hdata_get_var_array_size: get array size for variable in - * hdata - */ - -static int -weechat_lua_api_hdata_get_var_array_size (lua_State *L) -{ - const char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - value = weechat_hdata_get_var_array_size (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_hdata_get_var_array_size_string: get array size for variable - * in hdata (as string) - */ - -static int -weechat_lua_api_hdata_get_var_array_size_string (lua_State *L) -{ - const char *hdata, *pointer, *name, *result; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_hdata_get_var_hdata: get hdata for variable in hdata - */ - -static int -weechat_lua_api_hdata_get_var_hdata (lua_State *L) -{ - const char *hdata, *name, *result; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_hdata_get_list: get list pointer in hdata - */ - -static int -weechat_lua_api_hdata_get_list (lua_State *L) -{ - const char *hdata, *name; - char *result; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(hdata), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hdata_check_pointer: check pointer with hdata/list - */ - -static int -weechat_lua_api_hdata_check_pointer (lua_State *L) -{ - const char *hdata, *list, *pointer; - int value; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = lua_tostring (lua_current_interpreter, -3); - list = lua_tostring (lua_current_interpreter, -2); - pointer = lua_tostring (lua_current_interpreter, -1); - - value = weechat_hdata_check_pointer (API_STR2PTR(hdata), - API_STR2PTR(list), - API_STR2PTR(pointer)); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_hdata_move: move pointer to another element in list - */ - -static int -weechat_lua_api_hdata_move (lua_State *L) -{ - const char *hdata, *pointer; - char *result; - int count; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - count = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_hdata_move (API_STR2PTR(hdata), - API_STR2PTR(pointer), - count)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hdata_char: get char value of a variable in structure using - * hdata - */ - -static int -weechat_lua_api_hdata_char (lua_State *L) -{ - const char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - value = (int)weechat_hdata_char (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_hdata_integer: get integer value of a variable in structure - * using hdata - */ - -static int -weechat_lua_api_hdata_integer (lua_State *L) -{ - const char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - value = weechat_hdata_integer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_lua_api_hdata_long: get long value of a variable in structure using - * hdata - */ - -static int -weechat_lua_api_hdata_long (lua_State *L) -{ - const char *hdata, *pointer, *name; - long value; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - value = weechat_hdata_long (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_LONG(value); -} - -/* - * weechat_lua_api_hdata_string: get string value of a variable in structure - * using hdata - */ - -static int -weechat_lua_api_hdata_string (lua_State *L) -{ - const char *hdata, *pointer, *name, *result; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hdata_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_hdata_pointer: get pointer value of a variable in structure - * using hdata - */ - -static int -weechat_lua_api_hdata_pointer (lua_State *L) -{ - const char *hdata, *pointer, *name; - char *result; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hdata_time: get time value of a variable in structure using - * hdata - */ - -static int -weechat_lua_api_hdata_time (lua_State *L) -{ - const char *hdata, *pointer, *name; - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_hdata_hashtable: get hashtable value of a variable in - * structure using hdata - */ - -static int -weechat_lua_api_hdata_hashtable (lua_State *L) -{ - const char *hdata, *pointer, *name; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -3); - pointer = lua_tostring (lua_current_interpreter, -2); - name = lua_tostring (lua_current_interpreter, -1); - - weechat_lua_pushhashtable (lua_current_interpreter, - weechat_hdata_hashtable (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - return 1; -} - -/* - * weechat_lua_api_hdata_get_string: get hdata property as string - */ - -static int -weechat_lua_api_hdata_get_string (lua_State *L) -{ - const char *hdata, *property, *result; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = lua_tostring (lua_current_interpreter, -2); - property = lua_tostring (lua_current_interpreter, -1); - - result = weechat_hdata_get_string (API_STR2PTR(hdata), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_lua_api_upgrade_new: create an upgrade file - */ - -static int -weechat_lua_api_upgrade_new (lua_State *L) -{ - const char *filename; - char *result; - int write; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - filename = lua_tostring (lua_current_interpreter, -2); - write = lua_tonumber (lua_current_interpreter, -1); - - result = script_ptr2str (weechat_upgrade_new (filename, write)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_lua_api_upgrade_write_object: write object in upgrade file - */ - -static int -weechat_lua_api_upgrade_write_object (lua_State *L) -{ - const char *upgrade_file, *infolist; - int object_id, rc; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - upgrade_file = lua_tostring (lua_current_interpreter, -3); - object_id = lua_tonumber (lua_current_interpreter, -2); - infolist = lua_tostring (lua_current_interpreter, -1); - - rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file), - object_id, - API_STR2PTR(infolist)); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_upgrade_read_cb: callback for reading object in upgrade file - */ - -int -weechat_lua_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_lua_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_lua_api_upgrade_read: read upgrade file - */ - -static int -weechat_lua_api_upgrade_read (lua_State *L) -{ - const char *upgrade_file, *function, *data; - int rc; - - API_FUNC(1, "upgrade_read", API_RETURN_EMPTY); - if (lua_gettop (lua_current_interpreter) < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - upgrade_file = lua_tostring (lua_current_interpreter, -3); - function = lua_tostring (lua_current_interpreter, -2); - data = lua_tostring (lua_current_interpreter, -1); - - rc = script_api_upgrade_read (weechat_lua_plugin, - lua_current_script, - API_STR2PTR(upgrade_file), - &weechat_lua_api_upgrade_read_cb, - function, - data); - - API_RETURN_INT(rc); -} - -/* - * weechat_lua_api_upgrade_close: close upgrade file - */ - -static int -weechat_lua_api_upgrade_close (lua_State *L) -{ - const char *upgrade_file; - - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - if (lua_gettop (lua_current_interpreter) < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - upgrade_file = lua_tostring (lua_current_interpreter, -1); - - weechat_upgrade_close (API_STR2PTR(upgrade_file)); - - API_RETURN_OK; -} - -/* - * Lua constant as functions - */ - -static int -weechat_lua_api_constant_weechat_rc_ok (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK); - return 1; -} - -static int -weechat_lua_api_constant_weechat_rc_ok_eat (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_EAT); - return 1; -} - -static int -weechat_lua_api_constant_weechat_rc_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_RC_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_read_ok (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_READ_OK); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_read_memory_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_READ_MEMORY_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_read_file_not_found (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_READ_FILE_NOT_FOUND); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_write_ok (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_WRITE_OK); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_write_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_WRITE_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_write_memory_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_WRITE_MEMORY_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_set_ok_changed (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_SET_OK_CHANGED); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_set_ok_same_value (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_set_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_SET_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_set_option_not_found (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_unset_ok_no_reset (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_unset_ok_reset (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_unset_ok_removed (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED); - return 1; -} - -static int -weechat_lua_api_constant_weechat_config_option_unset_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_CONFIG_OPTION_UNSET_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_list_pos_sort (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_LIST_POS_SORT); - return 1; -} - -static int -weechat_lua_api_constant_weechat_list_pos_beginning (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_LIST_POS_BEGINNING); - return 1; -} - -static int -weechat_lua_api_constant_weechat_list_pos_end (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_LIST_POS_END); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hotlist_low (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOTLIST_LOW); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hotlist_message (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOTLIST_MESSAGE); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hotlist_private (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOTLIST_PRIVATE); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hotlist_highlight (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOTLIST_HIGHLIGHT); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_process_running (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_PROCESS_RUNNING); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_process_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_PROCESS_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_ok (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_OK); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_address_not_found (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_ip_address_not_found (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_connection_refused (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_proxy_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_PROXY_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_local_hostname_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_gnutls_init_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_gnutls_handshake_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_memory_error (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_MEMORY_ERROR); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_connect_timeout (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_TIMEOUT); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_signal_string (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOOK_SIGNAL_STRING); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_signal_int (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOOK_SIGNAL_INT); - return 1; -} - -static int -weechat_lua_api_constant_weechat_hook_signal_pointer (lua_State *L) -{ - /* make C compiler happy */ - (void) L; - - lua_pushstring (lua_current_interpreter, WEECHAT_HOOK_SIGNAL_POINTER); - return 1; -} - -/* - * Lua subroutines - */ - -const struct luaL_Reg weechat_lua_api_funcs[] = { - API_DEF_FUNC(register), - API_DEF_FUNC(plugin_get_name), - API_DEF_FUNC(charset_set), - API_DEF_FUNC(iconv_to_internal), - API_DEF_FUNC(iconv_from_internal), - API_DEF_FUNC(gettext), - API_DEF_FUNC(ngettext), - API_DEF_FUNC(string_match), - API_DEF_FUNC(string_has_highlight), - API_DEF_FUNC(string_has_highlight_regex), - API_DEF_FUNC(string_mask_to_regex), - API_DEF_FUNC(string_remove_color), - API_DEF_FUNC(string_is_command_char), - API_DEF_FUNC(string_input_for_buffer), - API_DEF_FUNC(mkdir_home), - API_DEF_FUNC(mkdir), - API_DEF_FUNC(mkdir_parents), - API_DEF_FUNC(list_new), - API_DEF_FUNC(list_add), - API_DEF_FUNC(list_search), - API_DEF_FUNC(list_search_pos), - API_DEF_FUNC(list_casesearch), - API_DEF_FUNC(list_casesearch_pos), - API_DEF_FUNC(list_get), - API_DEF_FUNC(list_set), - API_DEF_FUNC(list_next), - API_DEF_FUNC(list_prev), - API_DEF_FUNC(list_string), - API_DEF_FUNC(list_size), - API_DEF_FUNC(list_remove), - API_DEF_FUNC(list_remove_all), - API_DEF_FUNC(list_free), - API_DEF_FUNC(config_new), - API_DEF_FUNC(config_new_section), - API_DEF_FUNC(config_search_section), - API_DEF_FUNC(config_new_option), - API_DEF_FUNC(config_search_option), - API_DEF_FUNC(config_string_to_boolean), - API_DEF_FUNC(config_option_reset), - API_DEF_FUNC(config_option_set), - API_DEF_FUNC(config_option_set_null), - API_DEF_FUNC(config_option_unset), - API_DEF_FUNC(config_option_rename), - API_DEF_FUNC(config_option_is_null), - API_DEF_FUNC(config_option_default_is_null), - API_DEF_FUNC(config_boolean), - API_DEF_FUNC(config_boolean_default), - API_DEF_FUNC(config_integer), - API_DEF_FUNC(config_integer_default), - API_DEF_FUNC(config_string), - API_DEF_FUNC(config_string_default), - API_DEF_FUNC(config_color), - API_DEF_FUNC(config_color_default), - API_DEF_FUNC(config_write_option), - API_DEF_FUNC(config_write_line), - API_DEF_FUNC(config_write), - API_DEF_FUNC(config_read), - API_DEF_FUNC(config_reload), - API_DEF_FUNC(config_option_free), - API_DEF_FUNC(config_section_free_options), - API_DEF_FUNC(config_section_free), - API_DEF_FUNC(config_free), - API_DEF_FUNC(config_get), - API_DEF_FUNC(config_get_plugin), - API_DEF_FUNC(config_is_set_plugin), - API_DEF_FUNC(config_set_plugin), - API_DEF_FUNC(config_set_desc_plugin), - API_DEF_FUNC(config_unset_plugin), - API_DEF_FUNC(key_bind), - API_DEF_FUNC(key_unbind), - API_DEF_FUNC(prefix), - API_DEF_FUNC(color), - API_DEF_FUNC(print), - API_DEF_FUNC(print_date_tags), - API_DEF_FUNC(print_y), - API_DEF_FUNC(log_print), - API_DEF_FUNC(hook_command), - API_DEF_FUNC(hook_command_run), - API_DEF_FUNC(hook_timer), - API_DEF_FUNC(hook_fd), - API_DEF_FUNC(hook_process), - API_DEF_FUNC(hook_process_hashtable), - API_DEF_FUNC(hook_connect), - API_DEF_FUNC(hook_print), - API_DEF_FUNC(hook_signal), - API_DEF_FUNC(hook_signal_send), - API_DEF_FUNC(hook_hsignal), - API_DEF_FUNC(hook_hsignal_send), - API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_list_add), - API_DEF_FUNC(hook_modifier), - API_DEF_FUNC(hook_modifier_exec), - API_DEF_FUNC(hook_info), - API_DEF_FUNC(hook_info_hashtable), - API_DEF_FUNC(hook_infolist), - API_DEF_FUNC(hook_focus), - API_DEF_FUNC(unhook), - API_DEF_FUNC(unhook_all), - API_DEF_FUNC(buffer_new), - API_DEF_FUNC(buffer_search), - API_DEF_FUNC(buffer_search_main), - API_DEF_FUNC(current_buffer), - API_DEF_FUNC(buffer_clear), - API_DEF_FUNC(buffer_close), - API_DEF_FUNC(buffer_merge), - API_DEF_FUNC(buffer_unmerge), - API_DEF_FUNC(buffer_get_integer), - API_DEF_FUNC(buffer_get_string), - API_DEF_FUNC(buffer_get_pointer), - API_DEF_FUNC(buffer_set), - API_DEF_FUNC(buffer_string_replace_local_var), - API_DEF_FUNC(buffer_match_list), - API_DEF_FUNC(current_window), - API_DEF_FUNC(window_search_with_buffer), - API_DEF_FUNC(window_get_integer), - API_DEF_FUNC(window_get_string), - API_DEF_FUNC(window_get_pointer), - API_DEF_FUNC(window_set_title), - API_DEF_FUNC(nicklist_add_group), - API_DEF_FUNC(nicklist_search_group), - API_DEF_FUNC(nicklist_add_nick), - API_DEF_FUNC(nicklist_search_nick), - API_DEF_FUNC(nicklist_remove_group), - API_DEF_FUNC(nicklist_remove_nick), - API_DEF_FUNC(nicklist_remove_all), - API_DEF_FUNC(nicklist_group_get_integer), - API_DEF_FUNC(nicklist_group_get_string), - API_DEF_FUNC(nicklist_group_get_pointer), - API_DEF_FUNC(nicklist_group_set), - API_DEF_FUNC(nicklist_nick_get_integer), - API_DEF_FUNC(nicklist_nick_get_string), - API_DEF_FUNC(nicklist_nick_get_pointer), - API_DEF_FUNC(nicklist_nick_set), - API_DEF_FUNC(bar_item_search), - API_DEF_FUNC(bar_item_new), - API_DEF_FUNC(bar_item_update), - API_DEF_FUNC(bar_item_remove), - API_DEF_FUNC(bar_search), - API_DEF_FUNC(bar_new), - API_DEF_FUNC(bar_set), - API_DEF_FUNC(bar_update), - API_DEF_FUNC(bar_remove), - API_DEF_FUNC(command), - API_DEF_FUNC(info_get), - API_DEF_FUNC(info_get_hashtable), - API_DEF_FUNC(infolist_new), - API_DEF_FUNC(infolist_new_item), - API_DEF_FUNC(infolist_new_var_integer), - API_DEF_FUNC(infolist_new_var_string), - API_DEF_FUNC(infolist_new_var_pointer), - API_DEF_FUNC(infolist_new_var_time), - API_DEF_FUNC(infolist_get), - API_DEF_FUNC(infolist_next), - API_DEF_FUNC(infolist_prev), - API_DEF_FUNC(infolist_reset_item_cursor), - API_DEF_FUNC(infolist_fields), - API_DEF_FUNC(infolist_integer), - API_DEF_FUNC(infolist_string), - API_DEF_FUNC(infolist_pointer), - API_DEF_FUNC(infolist_time), - API_DEF_FUNC(infolist_free), - API_DEF_FUNC(hdata_get), - API_DEF_FUNC(hdata_get_var_offset), - API_DEF_FUNC(hdata_get_var_type_string), - API_DEF_FUNC(hdata_get_var_array_size), - API_DEF_FUNC(hdata_get_var_array_size_string), - API_DEF_FUNC(hdata_get_var_hdata), - API_DEF_FUNC(hdata_get_list), - API_DEF_FUNC(hdata_check_pointer), - API_DEF_FUNC(hdata_move), - API_DEF_FUNC(hdata_char), - API_DEF_FUNC(hdata_integer), - API_DEF_FUNC(hdata_long), - API_DEF_FUNC(hdata_string), - API_DEF_FUNC(hdata_pointer), - API_DEF_FUNC(hdata_time), - API_DEF_FUNC(hdata_hashtable), - API_DEF_FUNC(hdata_get_string), - API_DEF_FUNC(upgrade_new), - API_DEF_FUNC(upgrade_write_object), - API_DEF_FUNC(upgrade_read), - API_DEF_FUNC(upgrade_close), - - /* define constants as function which returns values */ - - { "WEECHAT_RC_OK", &weechat_lua_api_constant_weechat_rc_ok }, - { "WEECHAT_RC_OK_EAT", &weechat_lua_api_constant_weechat_rc_ok_eat }, - { "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error }, - - { "WEECHAT_CONFIG_READ_OK", &weechat_lua_api_constant_weechat_config_read_ok }, - { "WEECHAT_CONFIG_READ_MEMORY_ERROR", &weechat_lua_api_constant_weechat_config_read_memory_error }, - { "WEECHAT_CONFIG_READ_FILE_NOT_FOUND", &weechat_lua_api_constant_weechat_config_read_file_not_found }, - { "WEECHAT_CONFIG_WRITE_OK", &weechat_lua_api_constant_weechat_config_write_ok }, - { "WEECHAT_CONFIG_WRITE_ERROR", &weechat_lua_api_constant_weechat_config_write_error }, - { "WEECHAT_CONFIG_WRITE_MEMORY_ERROR", &weechat_lua_api_constant_weechat_config_write_memory_error }, - { "WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", &weechat_lua_api_constant_weechat_config_option_set_ok_changed }, - { "WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", &weechat_lua_api_constant_weechat_config_option_set_ok_same_value }, - { "WEECHAT_CONFIG_OPTION_SET_ERROR", &weechat_lua_api_constant_weechat_config_option_set_error }, - { "WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", &weechat_lua_api_constant_weechat_config_option_set_option_not_found }, - { "WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", &weechat_lua_api_constant_weechat_config_option_unset_ok_no_reset }, - { "WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", &weechat_lua_api_constant_weechat_config_option_unset_ok_reset }, - { "WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", &weechat_lua_api_constant_weechat_config_option_unset_ok_removed }, - { "WEECHAT_CONFIG_OPTION_UNSET_ERROR", &weechat_lua_api_constant_weechat_config_option_unset_error }, - - { "WEECHAT_LIST_POS_SORT", &weechat_lua_api_constant_weechat_list_pos_sort }, - { "WEECHAT_LIST_POS_BEGINNING", &weechat_lua_api_constant_weechat_list_pos_beginning }, - { "WEECHAT_LIST_POS_END", &weechat_lua_api_constant_weechat_list_pos_end }, - - { "WEECHAT_HOTLIST_LOW", &weechat_lua_api_constant_weechat_hotlist_low }, - { "WEECHAT_HOTLIST_MESSAGE", &weechat_lua_api_constant_weechat_hotlist_message }, - { "WEECHAT_HOTLIST_PRIVATE", &weechat_lua_api_constant_weechat_hotlist_private }, - { "WEECHAT_HOTLIST_HIGHLIGHT", &weechat_lua_api_constant_weechat_hotlist_highlight }, - - { "WEECHAT_HOOK_PROCESS_RUNNING", &weechat_lua_api_constant_weechat_hook_process_running }, - { "WEECHAT_HOOK_PROCESS_ERROR", &weechat_lua_api_constant_weechat_hook_process_error }, - - { "WEECHAT_HOOK_CONNECT_OK", &weechat_lua_api_constant_weechat_hook_connect_ok }, - { "WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", &weechat_lua_api_constant_weechat_hook_connect_address_not_found }, - { "WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", &weechat_lua_api_constant_weechat_hook_connect_ip_address_not_found }, - { "WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", &weechat_lua_api_constant_weechat_hook_connect_connection_refused }, - { "WEECHAT_HOOK_CONNECT_PROXY_ERROR", &weechat_lua_api_constant_weechat_hook_connect_proxy_error }, - { "WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", &weechat_lua_api_constant_weechat_hook_connect_local_hostname_error }, - { "WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", &weechat_lua_api_constant_weechat_hook_connect_gnutls_init_error }, - { "WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", &weechat_lua_api_constant_weechat_hook_connect_gnutls_handshake_error }, - { "WEECHAT_HOOK_CONNECT_MEMORY_ERROR", &weechat_lua_api_constant_weechat_hook_connect_memory_error }, - { "WEECHAT_HOOK_CONNECT_TIMEOUT", &weechat_lua_api_constant_weechat_hook_connect_timeout }, - - { "WEECHAT_HOOK_SIGNAL_STRING", &weechat_lua_api_constant_weechat_hook_signal_string }, - { "WEECHAT_HOOK_SIGNAL_INT", &weechat_lua_api_constant_weechat_hook_signal_int }, - { "WEECHAT_HOOK_SIGNAL_POINTER", &weechat_lua_api_constant_weechat_hook_signal_pointer }, - - { NULL, NULL } -}; diff --git a/src/plugins/scripts/lua/weechat-lua-api.h b/src/plugins/scripts/lua/weechat-lua-api.h deleted file mode 100644 index b37789215..000000000 --- a/src/plugins/scripts/lua/weechat-lua-api.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> - * Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_LUA_API_H -#define __WEECHAT_LUA_API_H 1 - -extern struct luaL_Reg weechat_lua_api_funcs[]; - -extern int weechat_lua_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_lua_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); - -#endif /* __WEECHAT_LUA_API_H */ diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c deleted file mode 100644 index 8957bbe88..000000000 --- a/src/plugins/scripts/lua/weechat-lua.c +++ /dev/null @@ -1,792 +0,0 @@ -/* - * Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> - * Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-lua.c: lua plugin for WeeChat - */ - -#undef _ - -#include <lua.h> -#include <lualib.h> -#include <lauxlib.h> -#include <stdlib.h> -#include <string.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-lua.h" -#include "weechat-lua-api.h" - - -WEECHAT_PLUGIN_NAME(LUA_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of lua scripts")); -WEECHAT_PLUGIN_AUTHOR("Sebastien Helleu <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_lua_plugin; - -int lua_quiet = 0; -struct t_plugin_script *lua_scripts = NULL; -struct t_plugin_script *last_lua_script = NULL; -struct t_plugin_script *lua_current_script = NULL; -struct t_plugin_script *lua_registered_script = NULL; -const char *lua_current_script_filename = NULL; -lua_State *lua_current_interpreter = NULL; - -/* - * string used to execute action "install": - * when signal "lua_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *lua_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "lua_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *lua_action_remove_list = NULL; - - -/* - * weechat_lua_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_lua_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - lua_State *interpreter; - - /* make C compiler happy */ - (void) hashtable; - - interpreter = (lua_State *)data; - - lua_pushstring (interpreter, key); - lua_pushstring (interpreter, value); - lua_rawset (interpreter, -3); -} - -/* - * weechat_lua_pushhashtable: put a WeeChat hashtable on lua stack, as lua table - */ - -void -weechat_lua_pushhashtable (lua_State *interpreter, struct t_hashtable *hashtable) -{ - lua_newtable (interpreter); - - weechat_hashtable_map_string (hashtable, - &weechat_lua_hashtable_map_cb, - interpreter); -} - -/* - * weechat_lua_hash_to_hashtable: get WeeChat hashtable with lua hash (on stack) - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after use - * with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_lua_tohashtable (lua_State *interpreter, int index, int hashtable_size) -{ - struct t_hashtable *hashtable; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - lua_pushnil (interpreter); - while (lua_next (interpreter, index - 1) != 0) - { - weechat_hashtable_set (hashtable, - lua_tostring (interpreter, -2), - lua_tostring (interpreter, -1)); - /* remove value from stack (keep key for next iteration) */ - lua_pop (interpreter, 1); - } - - return hashtable; -} - -/* - * weechat_lua_exec: execute a lua function - */ - -void * -weechat_lua_exec (struct t_plugin_script *script, int ret_type, - const char *function, - const char *format, void **argv) -{ - void *ret_value; - int argc, i, *ret_i; - lua_State *old_lua_current_interpreter; - struct t_plugin_script *old_lua_current_script; - - old_lua_current_interpreter = lua_current_interpreter; - lua_current_interpreter = script->interpreter; - - lua_getglobal (lua_current_interpreter, function); - - old_lua_current_script = lua_current_script; - lua_current_script = script; - - argc = 0; - if (format && format[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - lua_pushstring (lua_current_interpreter, (char *)argv[i]); - break; - case 'i': /* integer */ - lua_pushnumber (lua_current_interpreter, *((int *)argv[i])); - break; - case 'h': /* hash */ - weechat_lua_pushhashtable (lua_current_interpreter, (struct t_hashtable *)argv[i]); - break; - } - } - } - - if (lua_pcall (lua_current_interpreter, argc, 1, 0) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to run function \"%s\""), - weechat_prefix ("error"), LUA_PLUGIN_NAME, function); - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, - lua_tostring (lua_current_interpreter, -1)); - lua_current_script = old_lua_current_script; - lua_current_interpreter = old_lua_current_interpreter; - return NULL; - } - - if (ret_type == WEECHAT_SCRIPT_EXEC_STRING) - ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1)); - else if (ret_type == WEECHAT_SCRIPT_EXEC_INT) - { - ret_i = malloc (sizeof (*ret_i)); - if (ret_i) - *ret_i = lua_tonumber (lua_current_interpreter, -1); - ret_value = ret_i; - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_value = weechat_lua_tohashtable (lua_current_interpreter, -1, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - } - else - { - WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, function); - lua_current_script = old_lua_current_script; - lua_current_interpreter = old_lua_current_interpreter; - return NULL; - } - - lua_current_script = old_lua_current_script; - lua_current_interpreter = old_lua_current_interpreter; - - return ret_value; -} - -/* - * weechat_lua_register_lib: register a library to use inside Lua script - */ - -void weechat_lua_register_lib (lua_State *L, const char *libname, - const luaL_Reg *l) -{ -#if LUA_VERSION_NUM >= 502 - if (libname) - { - lua_newtable (L); - luaL_setfuncs (L, l, 0); - lua_pushvalue (L, -1); - lua_setglobal (L, libname); - } - else - luaL_setfuncs (L, l, 0); -#else - luaL_register (L, libname, l); -#endif -} - -/* - * weechat_lua_load: load a Lua script - */ - -int -weechat_lua_load (const char *filename) -{ - FILE *fp; - char *weechat_lua_code = { - "weechat_outputs = {\n" - " write = function (self, str)\n" - " weechat.print(\"\", \"lua: stdout/stderr: \" .. str)\n" - " end\n" - "}\n" - "io.stdout = weechat_outputs\n" - "io.stderr = weechat_outputs\n" - }; - - if ((fp = fopen (filename, "r")) == NULL) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not found"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, filename); - return 0; - } - - if ((weechat_lua_plugin->debug >= 2) || !lua_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - LUA_PLUGIN_NAME, filename); - } - - lua_current_script = NULL; - lua_registered_script = NULL; - - lua_current_interpreter = luaL_newstate(); - - if (lua_current_interpreter == NULL) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to create new " - "sub-interpreter"), - weechat_prefix ("error"), LUA_PLUGIN_NAME); - fclose (fp); - return 0; - } - -#ifdef LUA_VERSION_NUM /* LUA_VERSION_NUM is defined only in lua >= 5.1.0 */ - luaL_openlibs (lua_current_interpreter); -#else - luaopen_base (lua_current_interpreter); - luaopen_string (lua_current_interpreter); - luaopen_table (lua_current_interpreter); - luaopen_math (lua_current_interpreter); - luaopen_io (lua_current_interpreter); - luaopen_debug (lua_current_interpreter); -#endif - - weechat_lua_register_lib (lua_current_interpreter, "weechat", weechat_lua_api_funcs); - -#ifdef LUA_VERSION_NUM - if (luaL_dostring (lua_current_interpreter, weechat_lua_code) != 0) -#else - if (lua_dostring (lua_current_interpreter, weechat_lua_code) != 0) -#endif - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to redirect stdout " - "and stderr"), - weechat_prefix ("error"), LUA_PLUGIN_NAME); - } - - lua_current_script_filename = filename; - - if (luaL_loadfile (lua_current_interpreter, filename) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to load file \"%s\""), - weechat_prefix ("error"), LUA_PLUGIN_NAME, filename); - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, - lua_tostring (lua_current_interpreter, -1)); - lua_close (lua_current_interpreter); - fclose (fp); - return 0; - } - - if (lua_pcall (lua_current_interpreter, 0, 0, 0) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to execute file " - "\"%s\""), - weechat_prefix ("error"), LUA_PLUGIN_NAME, filename); - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, - lua_tostring (lua_current_interpreter, -1)); - lua_close (lua_current_interpreter); - fclose (fp); - - /* if script was registered, remove it from list */ - if (lua_current_script) - script_remove (weechat_lua_plugin, &lua_scripts, &last_lua_script, - lua_current_script); - - return 0; - } - fclose (fp); - - if (!lua_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), LUA_PLUGIN_NAME, filename); - lua_close (lua_current_interpreter); - return 0; - } - lua_current_script = lua_registered_script; - - lua_current_script->interpreter = (lua_State *) lua_current_interpreter; - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_lua_plugin, - lua_scripts, - lua_current_script, - &weechat_lua_api_buffer_input_data_cb, - &weechat_lua_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_lua_load_cb: callback for weechat_script_auto_load() function - */ - -void -weechat_lua_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_lua_load (filename); -} - -/* - * weechat_lua_unload: unload a Lua script - */ - -void -weechat_lua_unload (struct t_plugin_script *script) -{ - int *rc; - void *interpreter; - - if ((weechat_lua_plugin->debug >= 2) || !lua_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - LUA_PLUGIN_NAME, script->name); - } - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *)weechat_lua_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, - NULL, NULL); - if (rc) - free (rc); - } - - interpreter = script->interpreter; - - if (lua_current_script == script) - lua_current_script = (lua_current_script->prev_script) ? - lua_current_script->prev_script : lua_current_script->next_script; - - script_remove (weechat_lua_plugin, &lua_scripts, &last_lua_script, script); - - if (interpreter) - lua_close (interpreter); -} - -/* - * weechat_lua_unload_name: unload a Lua script by name - */ - -void -weechat_lua_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_lua_plugin, lua_scripts, name); - if (ptr_script) - { - weechat_lua_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - LUA_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, name); - } -} - -/* - * weechat_lua_reload_name: reload a Lua script by name - */ - -void -weechat_lua_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_lua_plugin, lua_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_lua_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - LUA_PLUGIN_NAME, name); - weechat_lua_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), LUA_PLUGIN_NAME, name); - } -} - -/* - * weechat_lua_unload_all: unload all Lua scripts - */ - -void -weechat_lua_unload_all () -{ - while (lua_scripts) - { - weechat_lua_unload (lua_scripts); - } -} - -/* - * weechat_lua_command_cb: callback for "/lua" command - */ - -int -weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_lua_plugin, lua_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_lua_plugin, lua_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_lua_plugin, lua_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_lua_unload_all (); - script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_lua_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_lua_plugin, lua_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_lua_plugin, lua_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Lua script */ - path_script = script_search_path (weechat_lua_plugin, - argv_eol[2]); - weechat_lua_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Lua script */ - weechat_lua_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Lua script */ - weechat_lua_unload_name (argv_eol[2]); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), LUA_PLUGIN_NAME, "lua"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_lua_completion_cb: callback for script completion - */ - -int -weechat_lua_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_lua_plugin, completion, lua_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_lua_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_lua_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "lua_script") == 0) - { - return script_infolist_list_scripts (weechat_lua_plugin, - lua_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_lua_signal_debug_dump_cb: dump Lua plugin data in WeeChat log file - */ - -int -weechat_lua_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, LUA_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_lua_plugin, lua_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_lua_signal_buffer_closed_cb: callback called when a buffer is closed - */ - -int -weechat_lua_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (lua_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_lua_timer_action_cb: timer for executing actions - */ - -int -weechat_lua_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &lua_action_install_list) - { - script_action_install (weechat_lua_plugin, - lua_scripts, - &weechat_lua_unload, - &weechat_lua_load, - &lua_action_install_list); - } - else if (data == &lua_action_remove_list) - { - script_action_remove (weechat_lua_plugin, - lua_scripts, - &weechat_lua_unload, - &lua_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_lua_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_lua_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "lua_script_install") == 0) - { - script_action_add (&lua_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_lua_timer_action_cb, - &lua_action_install_list); - } - else if (strcmp (signal, "lua_script_remove") == 0) - { - script_action_add (&lua_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_lua_timer_action_cb, - &lua_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_init: initialize Lua plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; - - weechat_lua_plugin = plugin; - - init.callback_command = &weechat_lua_command_cb; - init.callback_completion = &weechat_lua_completion_cb; - init.callback_infolist = &weechat_lua_infolist_cb; - init.callback_signal_debug_dump = &weechat_lua_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_lua_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_lua_signal_script_action_cb; - init.callback_load_file = &weechat_lua_load_cb; - - lua_quiet = 1; - script_init (weechat_lua_plugin, argc, argv, &init); - lua_quiet = 0; - - script_display_short_list (weechat_lua_plugin, - lua_scripts); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: shutdown Lua interface - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - lua_quiet = 1; - script_end (plugin, &lua_scripts, &weechat_lua_unload_all); - lua_quiet = 0; - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/lua/weechat-lua.h b/src/plugins/scripts/lua/weechat-lua.h deleted file mode 100644 index 0512d2272..000000000 --- a/src/plugins/scripts/lua/weechat-lua.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org> - * Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_LUA_H -#define __WEECHAT_LUA_H 1 - -#define weechat_plugin weechat_lua_plugin -#define LUA_PLUGIN_NAME "lua" - -#define LUA_CURRENT_SCRIPT_NAME ((lua_current_script) ? lua_current_script->name : "-") - -extern struct t_weechat_plugin *weechat_lua_plugin; - -extern int lua_quiet; -extern struct t_plugin_script *lua_scripts; -extern struct t_plugin_script *last_lua_script; -extern struct t_plugin_script *lua_current_script; -extern struct t_plugin_script *lua_registered_script; -extern const char *lua_current_script_filename; -extern lua_State *lua_current_interpreter; - -extern void weechat_lua_pushhashtable (lua_State *interpreter, - struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_lua_tohashtable (lua_State *interpreter, - int index, - int hashtable_size); -extern void *weechat_lua_exec (struct t_plugin_script *script, int ret_type, - const char *function, - const char *format, void **argv); -extern void weechat_lua_register_lib(lua_State *L, const char *libname, - const luaL_Reg *l); - -#endif /* __WEECHAT_LUA_H */ diff --git a/src/plugins/scripts/perl/CMakeLists.txt b/src/plugins/scripts/perl/CMakeLists.txt deleted file mode 100644 index 276477f89..000000000 --- a/src/plugins/scripts/perl/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(perl MODULE weechat-perl.c weechat-perl.h weechat-perl-api.c -weechat-perl-api.h) - -SET_TARGET_PROPERTIES(perl PROPERTIES PREFIX "") - -IF(PERL_FOUND) - IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # remove "-arch xxx" on Mac OS X - STRING(REGEX REPLACE "-arch ppc|-arch i386|-arch x86_64" "" PERL_CFLAGS "${PERL_CFLAGS}") - STRING(REGEX REPLACE "-arch ppc|-arch i386|-arch x86_64" "" PERL_LFLAGS "${PERL_LFLAGS}") - ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - ADD_DEFINITIONS(${PERL_CFLAGS}) - INCLUDE_DIRECTORIES(${PERL_INCLUDE_PATH}) - # ugly hack to force linking against Dynaloader.a - STRING(REGEX MATCH "/[^ $]*/DynaLoader.a" PERL_DYNALOADER ${PERL_LFLAGS}) - IF(PERL_DYNALOADER) - STRING(REPLACE "${PERL_DYNALOADER}" "" PERL_LFLAGS "${PERL_LFLAGS}") - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PERL_LFLAGS}") - EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy ${PERL_DYNALOADER} ${CMAKE_CURRENT_BINARY_DIR}/libDynaLoader.a) - TARGET_LINK_LIBRARIES(perl ${PERL_LIBRARY} weechat_scripts ${CMAKE_CURRENT_BINARY_DIR}/libDynaLoader.a) - ELSE(PERL_DYNALOADER) - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PERL_LFLAGS}") - TARGET_LINK_LIBRARIES(perl ${PERL_LIBRARY} weechat_scripts) - ENDIF(PERL_DYNALOADER) -ENDIF(PERL_FOUND) - -INSTALL(TARGETS perl LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/perl/Makefile.am b/src/plugins/scripts/perl/Makefile.am deleted file mode 100644 index ab7184f69..000000000 --- a/src/plugins/scripts/perl/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PERL_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = perl.la - -perl_la_SOURCES = weechat-perl.c \ - weechat-perl.h \ - weechat-perl-api.c \ - weechat-perl-api.h -perl_la_LDFLAGS = -module -perl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PERL_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c deleted file mode 100644 index 9434e3410..000000000 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ /dev/null @@ -1,5816 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2008 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-perl-api.c: perl API functions - */ - -#undef _ - -#include <EXTERN.h> -#include <perl.h> -#include <XSUB.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-perl.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *perl_function_name = __name; \ - (void) cv; \ - if (__init \ - && (!perl_current_script || !perl_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, \ - perl_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, \ - perl_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_perl_plugin, PERL_CURRENT_SCRIPT_NAME, \ - perl_function_name, __string) -#define API_RETURN_OK XSRETURN_YES -#define API_RETURN_ERROR XSRETURN_NO -#define API_RETURN_EMPTY XSRETURN_EMPTY -#define API_RETURN_STRING(__string) \ - if (__string) \ - { \ - XST_mPV (0, __string); \ - XSRETURN (1); \ - } \ - XST_mPV (0, ""); \ - XSRETURN (1) -#define API_RETURN_STRING_FREE(__string) \ - if (__string) \ - { \ - XST_mPV (0, __string); \ - free (__string); \ - XSRETURN (1); \ - } \ - XST_mPV (0, ""); \ - XSRETURN (1) -#define API_RETURN_INT(__int) \ - XST_mIV (0, __int); \ - XSRETURN (1); -#define API_RETURN_LONG(__long) \ - XST_mIV (0, __long); \ - XSRETURN (1); -#define API_RETURN_OBJ(__obj) \ - ST (0) = newRV_inc((SV *)__obj); \ - if (SvREFCNT(ST(0))) sv_2mortal(ST(0)); \ - XSRETURN (1); - -#define API_DEF_FUNC(__name) \ - newXS ("weechat::" #__name, XS_weechat_api_##__name, "weechat"); - - -extern void boot_DynaLoader (pTHX_ CV* cv); - - -/* - * weechat::register: startup function for all WeeChat Perl scripts - */ - -XS (XS_weechat_api_register) -{ - char *name, *author, *version, *license, *description, *shutdown_func; - char *charset; - dXSARGS; - - /* make C compiler happy */ - (void) items; - - API_FUNC(0, "register", API_RETURN_ERROR); - if (perl_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - perl_registered_script->name); - API_RETURN_ERROR; - } - perl_current_script = NULL; - perl_registered_script = NULL; - - if (items < 7) - API_WRONG_ARGS(API_RETURN_ERROR); - - name = SvPV_nolen (ST (0)); - author = SvPV_nolen (ST (1)); - version = SvPV_nolen (ST (2)); - license = SvPV_nolen (ST (3)); - description = SvPV_nolen (ST (4)); - shutdown_func = SvPV_nolen (ST (5)); - charset = SvPV_nolen (ST (6)); - - if (script_search (weechat_perl_plugin, perl_scripts, name)) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, name); - API_RETURN_ERROR; - } - - /* register script */ - perl_current_script = script_add (weechat_perl_plugin, - &perl_scripts, &last_perl_script, - (perl_current_script_filename) ? - perl_current_script_filename : "", - name, author, version, license, - description, shutdown_func, charset); - if (perl_current_script) - { - perl_registered_script = perl_current_script; - if ((weechat_perl_plugin->debug >= 2) || !perl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - PERL_PLUGIN_NAME, name, version, description); - } - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat::plugin_get_name: get name of plugin (return "core" for WeeChat core) - */ - -XS (XS_weechat_api_plugin_get_name) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_plugin_get_name (API_STR2PTR(SvPV_nolen (ST (0)))); /* plugin */ - - API_RETURN_STRING(result); -} - -/* - * weechat::charser_set: set script charset - */ - -XS (XS_weechat_api_charset_set) -{ - dXSARGS; - - API_FUNC(1, "charset_set", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_charset_set (perl_current_script, - SvPV_nolen (ST (0))); /* charset */ - - API_RETURN_OK; -} - -/* - * weechat::iconv_to_internal: convert string to internal WeeChat charset - */ - -XS (XS_weechat_api_iconv_to_internal) -{ - char *result, *charset, *string; - dXSARGS; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = SvPV_nolen (ST (0)); - string = SvPV_nolen (ST (1)); - - result = weechat_iconv_to_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::iconv_from_internal: convert string from WeeChat inernal charset - * to another one - */ - -XS (XS_weechat_api_iconv_from_internal) -{ - char *result, *charset, *string; - dXSARGS; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = SvPV_nolen (ST (0)); - string = SvPV_nolen (ST (1)); - - result = weechat_iconv_from_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::gettext: get translated string - */ - -XS (XS_weechat_api_gettext) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_gettext (SvPV_nolen (ST (0))); /* string */ - - API_RETURN_STRING(result); -} - -/* - * weechat::ngettext: get translated string with plural form - */ - -XS (XS_weechat_api_ngettext) -{ - char *single, *plural; - const char *result; - dXSARGS; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - single = SvPV_nolen (ST (0)); - plural = SvPV_nolen (ST (1)); - - result = weechat_ngettext (single, plural, - SvIV (ST (2))); /* count */ - - API_RETURN_STRING(result); -} - -/* - * weechat::string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other "*" - * are allowed inside mask - */ - -XS (XS_weechat_api_string_match) -{ - int value; - dXSARGS; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_match (SvPV_nolen (ST (0)), /* string */ - SvPV_nolen (ST (1)), /* mask */ - SvIV (ST (2))); /* case_sensitive */ - - API_RETURN_INT(value); -} - -/* - * weechat::string_has_highlight: return 1 if string contains a highlight - * (using list of words to highlight) - * return 0 if no highlight is found in string - */ - -XS (XS_weechat_api_string_has_highlight) -{ - int value; - dXSARGS; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight (SvPV_nolen (ST (0)), /* string */ - SvPV_nolen (ST (1))); /* highlight_words */ - - API_RETURN_INT(value); -} - -/* - * weechat::string_has_highlight_regex: return 1 if string contains a highlight - * (using regular expression) - * return 0 if no highlight is found in - * string - */ - -XS (XS_weechat_api_string_has_highlight_regex) -{ - int value; - dXSARGS; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight_regex (SvPV_nolen (ST (0)), /* string */ - SvPV_nolen (ST (1))); /* regex */ - - API_RETURN_INT(value); -} - -/* - * weechat::string_mask_to_regex: convert a mask (string with only "*" as - * wildcard) to a regex, paying attention to - * special chars in a regex - */ - -XS (XS_weechat_api_string_mask_to_regex) -{ - char *result; - dXSARGS; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_mask_to_regex (SvPV_nolen (ST (0))); /* mask */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::string_remove_color: remove WeeChat color codes from string - */ - -XS (XS_weechat_api_string_remove_color) -{ - char *result, *string, *replacement; - dXSARGS; - - API_FUNC(1, "string_remove_color", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - string = SvPV_nolen (ST (0)); - replacement = SvPV_nolen (ST (1)); - - result = weechat_string_remove_color (string, replacement); - - API_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; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_is_command_char (SvPV_nolen (ST (0))); /* string */ - - API_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; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_input_for_buffer (SvPV_nolen (ST (0))); /* string */ - - API_RETURN_STRING(result); -} - -/* - * weechat::mkdir_home: create a directory in WeeChat home - */ - -XS (XS_weechat_api_mkdir_home) -{ - dXSARGS; - - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_home (SvPV_nolen (ST (0)), /* directory */ - SvIV (ST (1)))) /* mode */ - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat::mkdir: create a directory - */ - -XS (XS_weechat_api_mkdir) -{ - dXSARGS; - - API_FUNC(1, "mkdir", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir (SvPV_nolen (ST (0)), /* directory */ - SvIV (ST (1)))) /* mode */ - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat::mkdir_parents: create a directory and make parent directories as - * needed - */ - -XS (XS_weechat_api_mkdir_parents) -{ - dXSARGS; - - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_parents (SvPV_nolen (ST (0)), /* directory */ - SvIV (ST (1)))) /* mode */ - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat::list_new: create a new list - */ - -XS (XS_weechat_api_list_new) -{ - char *result; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_add: add a string to list - */ - -XS (XS_weechat_api_list_add) -{ - char *result, *weelist, *data, *where, *user_data; - dXSARGS; - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - if (items < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = SvPV_nolen (ST (0)); - data = SvPV_nolen (ST (1)); - where = SvPV_nolen (ST (2)); - user_data = SvPV_nolen (ST (3)); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(weelist), - data, - where, - API_STR2PTR(user_data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_search: search a string in list - */ - -XS (XS_weechat_api_list_search) -{ - char *result, *weelist, *data; - dXSARGS; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = SvPV_nolen (ST (0)); - data = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_search_pos: search position of a string in list - */ - -XS (XS_weechat_api_list_search_pos) -{ - char *weelist, *data; - int pos; - dXSARGS; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = SvPV_nolen (ST (0)); - data = SvPV_nolen (ST (1)); - - pos = weechat_list_search_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat::list_casesearch: search a string in list (ignore case) - */ - -XS (XS_weechat_api_list_casesearch) -{ - char *result, *weelist, *data; - dXSARGS; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = SvPV_nolen (ST (0)); - data = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -XS (XS_weechat_api_list_casesearch_pos) -{ - char *weelist, *data; - int pos; - dXSARGS; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = SvPV_nolen (ST (0)); - data = SvPV_nolen (ST (1)); - - pos = weechat_list_casesearch_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat::list_get: get item by position - */ - -XS (XS_weechat_api_list_get) -{ - char *result; - dXSARGS; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(SvPV_nolen (ST (0))), /* weelist */ - SvIV (ST (1)))); /* position */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_set: set new value for item - */ - -XS (XS_weechat_api_list_set) -{ - char *item, *new_value; - dXSARGS; - - API_FUNC(1, "list_set", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - item = SvPV_nolen (ST (0)); - new_value = SvPV_nolen (ST (1)); - - weechat_list_set (API_STR2PTR(item), new_value); - - API_RETURN_OK; -} - -/* - * weechat::list_next: get next item - */ - -XS (XS_weechat_api_list_next) -{ - char *result; - dXSARGS; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(SvPV_nolen (ST (0))))); /* item */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_prev: get previous item - */ - -XS (XS_weechat_api_list_prev) -{ - char *result; - dXSARGS; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(SvPV_nolen (ST (0))))); /* item */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::list_string: get string value of item - */ - -XS (XS_weechat_api_list_string) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_list_string (API_STR2PTR(SvPV_nolen (ST (0)))); /* item */ - - API_RETURN_STRING(result); -} - -/* - * weechat::list_size: get number of elements in list - */ - -XS (XS_weechat_api_list_size) -{ - int size; - dXSARGS; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - size = weechat_list_size (API_STR2PTR(SvPV_nolen (ST (0)))); /* weelist */ - - API_RETURN_INT(size); -} - -/* - * weechat::list_remove: remove item from list - */ - -XS (XS_weechat_api_list_remove) -{ - char *weelist, *item; - dXSARGS; - - API_FUNC(1, "list_remove", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weelist = SvPV_nolen (ST (0)); - item = SvPV_nolen (ST (1)); - - weechat_list_remove (API_STR2PTR(weelist), - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat::list_remove_all: remove all items from list - */ - -XS (XS_weechat_api_list_remove_all) -{ - dXSARGS; - - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove_all (API_STR2PTR(SvPV_nolen (ST (0)))); /* weelist */ - - API_RETURN_OK; -} - -/* - * weechat::list_free: free list - */ - -XS (XS_weechat_api_list_free) -{ - dXSARGS; - - API_FUNC(1, "list_free", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_free (API_STR2PTR(SvPV_nolen (ST (0)))); /* weelist */ - - API_RETURN_OK; -} - -/* - * weechat_perl_api_config_reload_cb: callback for config reload - */ - -int -weechat_perl_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat::config_new: create a new configuration file - */ - -XS (XS_weechat_api_config_new) -{ - char *result, *name, *function, *data; - dXSARGS; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_config_new (weechat_perl_plugin, - perl_current_script, - name, - &weechat_perl_api_config_reload_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_config_section_read_cb: callback for reading option in section - */ - -int -weechat_perl_api_config_section_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_perl_api_config_section_write_cb: callback for writing section - */ - -int -weechat_perl_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_perl_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_perl_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_perl_api_config_section_create_option_cb: callback to create an option - */ - -int -weechat_perl_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_perl_api_config_section_delete_option_cb: callback to delete an option - */ - -int -weechat_perl_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat::config_new_section: create a new section in configuration file - */ - -XS (XS_weechat_api_config_new_section) -{ - char *result, *cfg_file, *name, *function_read, *data_read; - char *function_write, *data_write, *function_write_default; - char *data_write_default, *function_create_option, *data_create_option; - char *function_delete_option, *data_delete_option; - - dXSARGS; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - if (items < 14) - API_WRONG_ARGS(API_RETURN_EMPTY); - - cfg_file = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - function_read = SvPV_nolen (ST (4)); - data_read = SvPV_nolen (ST (5)); - function_write = SvPV_nolen (ST (6)); - data_write = SvPV_nolen (ST (7)); - function_write_default = SvPV_nolen (ST (8)); - data_write_default = SvPV_nolen (ST (9)); - function_create_option = SvPV_nolen (ST (10)); - data_create_option = SvPV_nolen (ST (11)); - function_delete_option = SvPV_nolen (ST (12)); - data_delete_option = SvPV_nolen (ST (13)); - - result = script_ptr2str (script_api_config_new_section (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(cfg_file), - name, - SvIV (ST (2)), /* user_can_add_options */ - SvIV (ST (3)), /* user_can_delete_options */ - &weechat_perl_api_config_section_read_cb, - function_read, - data_read, - &weechat_perl_api_config_section_write_cb, - function_write, - data_write, - &weechat_perl_api_config_section_write_default_cb, - function_write_default, - data_write_default, - &weechat_perl_api_config_section_create_option_cb, - function_create_option, - data_create_option, - &weechat_perl_api_config_section_delete_option_cb, - function_delete_option, - data_delete_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::config_search_section: search section in configuration file - */ - -XS (XS_weechat_api_config_search_section) -{ - char *result, *config_file, *section_name; - dXSARGS; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = SvPV_nolen (ST (0)); - section_name = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(config_file), - section_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_config_option_check_value_cb: callback for checking new - * value for option - */ - -int -weechat_perl_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_perl_api_config_option_change_cb: callback for option changed - */ - -void -weechat_perl_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_perl_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_perl_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat::config_new_option: create a new option in section - */ - -XS (XS_weechat_api_config_new_option) -{ - char *result, *config_file, *section, *name, *type; - char *description, *string_values, *default_value, *value; - char *function_check_value, *data_check_value, *function_change; - char *data_change, *function_delete, *data_delete; - dXSARGS; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - if (items < 17) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = SvPV_nolen (ST (0)); - section = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - type = SvPV_nolen (ST (3)); - description = SvPV_nolen (ST (4)); - string_values = SvPV_nolen (ST (5)); - default_value = SvPV_nolen (ST (8)); - value = SvPV_nolen (ST (9)); - function_check_value = SvPV_nolen (ST (11)); - data_check_value = SvPV_nolen (ST (12)); - function_change = SvPV_nolen (ST (13)); - data_change = SvPV_nolen (ST (14)); - function_delete = SvPV_nolen (ST (15)); - data_delete = SvPV_nolen (ST (16)); - - result = script_ptr2str (script_api_config_new_option (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(config_file), - API_STR2PTR(section), - name, - type, - description, - string_values, - SvIV (ST (6)), /* min */ - SvIV (ST (7)), /* max */ - default_value, - value, - SvIV (ST (10)), /* null_value_allowed */ - &weechat_perl_api_config_option_check_value_cb, - function_check_value, - data_check_value, - &weechat_perl_api_config_option_change_cb, - function_change, - data_change, - &weechat_perl_api_config_option_delete_cb, - function_delete, - data_delete)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::config_search_option: search option in configuration file or section - */ - -XS (XS_weechat_api_config_search_option) -{ - char *result, *config_file, *section, *option_name; - dXSARGS; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = SvPV_nolen (ST (0)); - section = SvPV_nolen (ST (1)); - option_name = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(config_file), - API_STR2PTR(section), - option_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::config_string_to_boolean: return boolean value of a string - */ - -XS (XS_weechat_api_config_string_to_boolean) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_string_to_boolean (SvPV_nolen (ST (0))); /* text */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_option_reset: reset an option with default value - */ - -XS (XS_weechat_api_config_option_reset) -{ - int rc; - char *option; - dXSARGS; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = SvPV_nolen (ST (0)); - - rc = weechat_config_option_reset (API_STR2PTR(option), - SvIV (ST (1))); /* run_callback */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_option_set: set new value for option - */ - -XS (XS_weechat_api_config_option_set) -{ - int rc; - char *option, *new_value; - dXSARGS; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = SvPV_nolen (ST (0)); - new_value = SvPV_nolen (ST (1)); - - rc = weechat_config_option_set (API_STR2PTR(option), - new_value, - SvIV (ST (2))); /* run_callback */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_option_set_null: set null (undefined) value for option - */ - -XS (XS_weechat_api_config_option_set_null) -{ - int rc; - char *option; - dXSARGS; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = SvPV_nolen (ST (0)); - - rc = weechat_config_option_set_null (API_STR2PTR(option), - SvIV (ST (1))); /* run_callback */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_option_unset: unset an option - */ - -XS (XS_weechat_api_config_option_unset) -{ - int rc; - char *option; - dXSARGS; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = SvPV_nolen (ST (0)); - - rc = weechat_config_option_unset (API_STR2PTR(option)); - - API_RETURN_INT(rc); -} - -/* - * weechat::config_option_rename: rename an option - */ - -XS (XS_weechat_api_config_option_rename) -{ - char *option, *new_name; - dXSARGS; - - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = SvPV_nolen (ST (0)); - new_name = SvPV_nolen (ST (1)); - - weechat_config_option_rename (API_STR2PTR(option), - new_name); - - API_RETURN_OK; -} - -/* - * weechat::config_option_is_null: return 1 if value of option is null - */ - -XS (XS_weechat_api_config_option_is_null) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_is_null (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_option_default_is_null: return 1 if default value of option - * is null - */ - -XS (XS_weechat_api_config_option_default_is_null) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_default_is_null (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_boolean: return boolean value of option - */ - -XS (XS_weechat_api_config_boolean) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_boolean_default: return default boolean value of option - */ - -XS (XS_weechat_api_config_boolean_default) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean_default (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_integer: return integer value of option - */ - -XS (XS_weechat_api_config_integer) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_integer_default: return default integer value of option - */ - -XS (XS_weechat_api_config_integer_default) -{ - int value; - dXSARGS; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer_default (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_INT(value); -} - -/* - * weechat::config_string: return string value of option - */ - -XS (XS_weechat_api_config_string) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat::config_string_default: return default string value of option - */ - -XS (XS_weechat_api_config_string_default) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string_default (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat::config_color: return color value of option - */ - -XS (XS_weechat_api_config_color) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat::config_color_default: return default color value of option - */ - -XS (XS_weechat_api_config_color_default) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color_default (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat::config_write_option: write an option in configuration file - */ - -XS (XS_weechat_api_config_write_option) -{ - char *config_file, *option; - dXSARGS; - - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = SvPV_nolen (ST (0)); - option = SvPV_nolen (ST (1)); - - weechat_config_write_option (API_STR2PTR(config_file), - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat::config_write_line: write a line in configuration file - */ - -XS (XS_weechat_api_config_write_line) -{ - char *config_file, *option_name, *value; - dXSARGS; - - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - if (items < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = SvPV_nolen (ST (0)); - option_name = SvPV_nolen (ST (1)); - value = SvPV_nolen (ST (2)); - - weechat_config_write_line (API_STR2PTR(config_file), option_name, - "%s", value); - - API_RETURN_OK; -} - -/* - * weechat::config_write: write configuration file - */ - -XS (XS_weechat_api_config_write) -{ - int rc; - dXSARGS; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_write (API_STR2PTR(SvPV_nolen (ST (0)))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_read: read configuration file - */ - -XS (XS_weechat_api_config_read) -{ - int rc; - dXSARGS; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_read (API_STR2PTR(SvPV_nolen (ST (0)))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_reload: reload configuration file - */ - -XS (XS_weechat_api_config_reload) -{ - int rc; - dXSARGS; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_reload (API_STR2PTR(SvPV_nolen (ST (0)))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat::config_option_free: free an option in configuration file - */ - -XS (XS_weechat_api_config_option_free) -{ - dXSARGS; - - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_option_free (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* option */ - - API_RETURN_OK; -} - -/* - * weechat::config_section_free_options: free options of a section in - * configuration file - */ - -XS (XS_weechat_api_config_section_free_options) -{ - dXSARGS; - - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free_options (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* section */ - - API_RETURN_OK; -} - -/* - * weechat::config_section_free: free section in configuration file - */ - -XS (XS_weechat_api_config_section_free) -{ - dXSARGS; - - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* section */ - - API_RETURN_OK; -} - -/* - * weechat::config_free: free configuration file - */ - -XS (XS_weechat_api_config_free) -{ - dXSARGS; - - API_FUNC(1, "config_free", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_free (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* config_file */ - - API_RETURN_OK; -} - -/* - * weechat::config_get: get config option - */ - -XS (XS_weechat_api_config_get) -{ - char *result; - dXSARGS; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_get (SvPV_nolen (ST (0)))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::config_get_plugin: get value of a plugin option - */ - -XS (XS_weechat_api_config_get_plugin) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_api_config_get_plugin (weechat_perl_plugin, - perl_current_script, - SvPV_nolen (ST (0))); - - API_RETURN_STRING(result); -} - -/* - * weechat::config_is_set_plugin: check if a plugin option is set - */ - -XS (XS_weechat_api_config_is_set_plugin) -{ - char *option; - int rc; - dXSARGS; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = SvPV_nolen (ST (0)); - - rc = script_api_config_is_set_plugin (weechat_perl_plugin, - perl_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat::config_set_plugin: set value of a plugin option - */ - -XS (XS_weechat_api_config_set_plugin) -{ - char *option, *value; - int rc; - dXSARGS; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = SvPV_nolen (ST (0)); - value = SvPV_nolen (ST (1)); - - rc = script_api_config_set_plugin (weechat_perl_plugin, - perl_current_script, - option, - value); - - API_RETURN_INT(rc); -} - -/* - * weechat::config_set_desc_plugin: set description of a plugin option - */ - -XS (XS_weechat_api_config_set_desc_plugin) -{ - char *option, *description; - dXSARGS; - - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - - script_api_config_set_desc_plugin (weechat_perl_plugin, - perl_current_script, - option, - description); - - API_RETURN_OK; -} - -/* - * weechat::config_unset_plugin: unset a plugin option - */ - -XS (XS_weechat_api_config_unset_plugin) -{ - char *option; - int rc; - dXSARGS; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = SvPV_nolen (ST (0)); - - rc = script_api_config_unset_plugin (weechat_perl_plugin, - perl_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat::key_bind: bind key(s) - */ - -XS (XS_weechat_api_key_bind) -{ - char *context; - struct t_hashtable *hashtable; - int num_keys; - dXSARGS; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = SvPV_nolen (ST (0)); - hashtable = weechat_perl_hash_to_hashtable (ST (1), - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (context, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_INT(num_keys); -} - -/* - * weechat::key_unbind: unbind key(s) - */ - -XS (XS_weechat_api_key_unbind) -{ - char *context, *key; - int num_keys; - dXSARGS; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = SvPV_nolen (ST (0)); - key = SvPV_nolen (ST (1)); - - num_keys = weechat_key_unbind (context, key); - - API_RETURN_INT(num_keys); -} - -/* - * weechat::prefix: get a prefix, used for display - */ - -XS (XS_weechat_api_prefix) -{ - const char *result; - dXSARGS; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_prefix (SvPV_nolen (ST (0))); /* prefix */ - - API_RETURN_STRING(result); -} - -/* - * weechat::color: get a color code, used for display - */ - -XS (XS_weechat_api_color) -{ - const char *result; - dXSARGS; - - API_FUNC(0, "color", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_color (SvPV_nolen (ST (0))); /* color */ - - API_RETURN_STRING(result); -} - -/* - * weechat::print: print message in a buffer - */ - -XS (XS_weechat_api_print) -{ - char *buffer, *message; - dXSARGS; - - API_FUNC(0, "print", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - message = SvPV_nolen (ST (1)); - - script_api_printf (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(buffer), - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat::print_date_tags: print message in a buffer with optional date and - * tags - */ - -XS (XS_weechat_api_print_date_tags) -{ - char *buffer, *tags, *message; - dXSARGS; - - API_FUNC(1, "print_date_tags", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - tags = SvPV_nolen (ST (2)); - message = SvPV_nolen (ST (3)); - - script_api_printf_date_tags (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(buffer), - SvIV (ST (1)), - tags, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat::print_y: print message in a buffer with free content - */ - -XS (XS_weechat_api_print_y) -{ - char *buffer, *message; - dXSARGS; - - API_FUNC(1, "print_y", API_RETURN_ERROR); - if (items < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - message = SvPV_nolen (ST (2)); - - script_api_printf_y (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(buffer), - SvIV (ST (1)), - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat::log_print: print message in WeeChat log file - */ - -XS (XS_weechat_api_log_print) -{ - dXSARGS; - - API_FUNC(1, "log_print", API_RETURN_ERROR); - - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_log_printf (weechat_perl_plugin, - perl_current_script, - "%s", SvPV_nolen (ST (0))); /* message */ - - API_RETURN_OK; -} - -/* - * weechat_perl_api_hook_command_cb: callback for command hooked - */ - -int -weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_command: hook a command - */ - -XS (XS_weechat_api_hook_command) -{ - char *result, *command, *description, *args, *args_description; - char *completion, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - if (items < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - args = SvPV_nolen (ST (2)); - args_description = SvPV_nolen (ST (3)); - completion = SvPV_nolen (ST (4)); - function = SvPV_nolen (ST (5)); - data = SvPV_nolen (ST (6)); - - result = script_ptr2str (script_api_hook_command (weechat_perl_plugin, - perl_current_script, - command, - description, - args, - args_description, - completion, - &weechat_perl_api_hook_command_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_perl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_command_run: hook a command_run - */ - -XS (XS_weechat_api_hook_command_run) -{ - char *result, *command, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_command_run (weechat_perl_plugin, - perl_current_script, - command, - &weechat_perl_api_hook_command_run_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_perl_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_timer: hook a timer - */ - -XS (XS_weechat_api_hook_timer) -{ - char *result; - dXSARGS; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - if (items < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_timer (weechat_perl_plugin, - perl_current_script, - SvIV (ST (0)), /* interval */ - SvIV (ST (1)), /* align_second */ - SvIV (ST (2)), /* max_calls */ - &weechat_perl_api_hook_timer_cb, - SvPV_nolen (ST (3)), /* perl function */ - SvPV_nolen (ST (4)))); /* data */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_perl_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_fd: hook a fd - */ - -XS (XS_weechat_api_hook_fd) -{ - char *result; - dXSARGS; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - if (items < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_fd (weechat_perl_plugin, - perl_current_script, - SvIV (ST (0)), /* fd */ - SvIV (ST (1)), /* read */ - SvIV (ST (2)), /* write */ - SvIV (ST (3)), /* exception */ - &weechat_perl_api_hook_fd_cb, - SvPV_nolen (ST (4)), /* perl function */ - SvPV_nolen (ST (5)))); /* data */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_process_cb: callback for process hooked - */ - -int -weechat_perl_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = &return_code; - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssiss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_process: hook a process - */ - -XS (XS_weechat_api_hook_process) -{ - char *command, *function, *data, *result; - dXSARGS; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - if (items < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (2)); - data = SvPV_nolen (ST (3)); - - result = script_ptr2str (script_api_hook_process (weechat_perl_plugin, - perl_current_script, - command, - SvIV (ST (1)), /* timeout */ - &weechat_perl_api_hook_process_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hook_process_hashtable: hook a process with options in a hashtable - */ - -XS (XS_weechat_api_hook_process_hashtable) -{ - char *command, *function, *data, *result; - struct t_hashtable *options; - dXSARGS; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - if (items < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = SvPV_nolen (ST (0)); - options = weechat_perl_hash_to_hashtable (ST (1), - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - function = SvPV_nolen (ST (3)); - data = SvPV_nolen (ST (4)); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_perl_plugin, - perl_current_script, - command, - options, - SvIV (ST (2)), /* timeout */ - &weechat_perl_api_hook_process_cb, - function, - data)); - - if (options) - weechat_hashtable_free (options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_perl_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_connect: hook a connection - */ - -XS (XS_weechat_api_hook_connect) -{ - char *proxy, *address, *local_hostname, *function, *data, *result; - dXSARGS; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - if (items < 8) - API_WRONG_ARGS(API_RETURN_EMPTY); - - proxy = SvPV_nolen (ST (0)); - address = SvPV_nolen (ST (1)); - local_hostname = SvPV_nolen (ST (5)); - function = SvPV_nolen (ST (6)); - data = SvPV_nolen (ST (7)); - - result = script_ptr2str (script_api_hook_connect (weechat_perl_plugin, - perl_current_script, - proxy, - address, - SvIV (ST (2)), /* port */ - SvIV (ST (3)), /* sock */ - SvIV (ST (4)), /* ipv6 */ - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - local_hostname, - &weechat_perl_api_hook_connect_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_print_cb: callback for print hooked - */ - -int -weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_print: hook a print - */ - -XS (XS_weechat_api_hook_print) -{ - char *result, *buffer, *tags, *message, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - if (items < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - tags = SvPV_nolen (ST (1)); - message = SvPV_nolen (ST (2)); - function = SvPV_nolen (ST (4)); - data = SvPV_nolen (ST (5)); - - result = script_ptr2str (script_api_hook_print (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(buffer), - tags, - message, - SvIV (ST (3)), /* strip_colors */ - &weechat_perl_api_hook_print_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_perl_api_hook_signal_cb (void *data, const char *signal, const char *type_data, - void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_signal: hook a signal - */ - -XS (XS_weechat_api_hook_signal) -{ - char *result, *signal, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_signal (weechat_perl_plugin, - perl_current_script, - signal, - &weechat_perl_api_hook_signal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hook_signal_send: send a signal - */ - -XS (XS_weechat_api_hook_signal_send) -{ - char *signal, *type_data; - int number; - dXSARGS; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - if (items < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = SvPV_nolen (ST (0)); - type_data = SvPV_nolen (ST (1)); - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - weechat_hook_signal_send (signal, - type_data, - SvPV_nolen (ST (2))); /* signal_data */ - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - number = SvIV(ST (2)); - weechat_hook_signal_send (signal, - type_data, - &number); /* signal_data */ - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - weechat_hook_signal_send (signal, - type_data, - API_STR2PTR(SvPV_nolen (ST (2)))); /* signal_data */ - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_perl_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_perl_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = hashtable; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssh", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_hsignal: hook a hsignal - */ - -XS (XS_weechat_api_hook_hsignal) -{ - char *result, *signal, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_hsignal (weechat_perl_plugin, - perl_current_script, - signal, - &weechat_perl_api_hook_hsignal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hook_hsignal_send: send a hsignal - */ - -XS (XS_weechat_api_hook_hsignal_send) -{ - char *signal; - struct t_hashtable *hashtable; - dXSARGS; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = SvPV_nolen (ST (0)); - hashtable = weechat_perl_hash_to_hashtable (ST (1), - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (signal, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_OK; -} - -/* - * weechat_perl_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_perl_api_hook_config_cb (void *data, const char *option, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_config: hook a config option - */ - -XS (XS_weechat_api_hook_config) -{ - char *result, *option, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - option = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_config (weechat_perl_plugin, - perl_current_script, - option, - &weechat_perl_api_hook_config_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_perl_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::hook_completion: hook a completion - */ - -XS (XS_weechat_api_hook_completion) -{ - char *result, *completion, *description, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (items < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - function = SvPV_nolen (ST (2)); - data = SvPV_nolen (ST (3)); - - result = script_ptr2str (script_api_hook_completion (weechat_perl_plugin, - perl_current_script, - completion, - description, - &weechat_perl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hook_completion_list_add: add a word to list for a completion - */ - -XS (XS_weechat_api_hook_completion_list_add) -{ - char *completion, *word, *where; - dXSARGS; - - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = SvPV_nolen (ST (0)); - word = SvPV_nolen (ST (1)); - where = SvPV_nolen (ST (3)); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - SvIV (ST (2)), /* nick_completion */ - where); - - API_RETURN_OK; -} - -/* - * weechat_perl_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_perl_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat::hook_modifier: hook a modifier - */ - -XS (XS_weechat_api_hook_modifier) -{ - char *result, *modifier, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - modifier = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_modifier (weechat_perl_plugin, - perl_current_script, - modifier, - &weechat_perl_api_hook_modifier_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hook_modifier_exec: execute a modifier hook - */ - -XS (XS_weechat_api_hook_modifier_exec) -{ - char *result, *modifier, *modifier_data, *string; - dXSARGS; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - modifier = SvPV_nolen (ST (0)); - modifier_data = SvPV_nolen (ST (1)); - string = SvPV_nolen (ST (2)); - - result = weechat_hook_modifier_exec (modifier, modifier_data, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_perl_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat::hook_info: hook an info - */ - -XS (XS_weechat_api_hook_info) -{ - char *result, *info_name, *description, *args_description, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - if (items < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - args_description = SvPV_nolen (ST (2)); - function = SvPV_nolen (ST (3)); - data = SvPV_nolen (ST (4)); - - result = script_ptr2str (script_api_hook_info (weechat_perl_plugin, - perl_current_script, - info_name, - description, - args_description, - &weechat_perl_api_hook_info_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_perl_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = hashtable; - - return (struct t_hashtable *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssh", func_argv); - } - - return NULL; -} - -/* - * weechat::hook_info_hashtable: hook an info_hashtable - */ - -XS (XS_weechat_api_hook_info_hashtable) -{ - char *result, *info_name, *description, *args_description; - char *output_description, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - if (items < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - args_description = SvPV_nolen (ST (2)); - output_description = SvPV_nolen (ST (3)); - function = SvPV_nolen (ST (4)); - data = SvPV_nolen (ST (5)); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_perl_plugin, - perl_current_script, - info_name, - description, - args_description, - output_description, - &weechat_perl_api_hook_info_hashtable_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_perl_api_hook_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat::hook_infolist: hook an infolist - */ - -XS (XS_weechat_api_hook_infolist) -{ - char *result, *infolist_name, *description, *pointer_description; - char *args_description, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - if (items < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist_name = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - pointer_description = SvPV_nolen (ST (2)); - args_description = SvPV_nolen (ST (3)); - function = SvPV_nolen (ST (4)); - data = SvPV_nolen (ST (5)); - - result = script_ptr2str (script_api_hook_infolist (weechat_perl_plugin, - perl_current_script, - infolist_name, - description, - pointer_description, - args_description, - &weechat_perl_api_hook_infolist_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_perl_api_hook_focus_cb (void *data, - struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = info; - - return (struct t_hashtable *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sh", func_argv); - } - - return NULL; -} - -/* - * weechat::hook_focus: hook a focus - */ - -XS (XS_weechat_api_hook_focus) -{ - char *result, *area, *function, *data; - dXSARGS; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - area = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_hook_focus (weechat_perl_plugin, - perl_current_script, - area, - &weechat_perl_api_hook_focus_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::unhook: unhook something - */ - -XS (XS_weechat_api_unhook) -{ - dXSARGS; - - API_FUNC(1, "unhook", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_unhook (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* hook */ - - API_RETURN_OK; -} - -/* - * weechat::unhook_all: unhook all for script - */ - -XS (XS_weechat_api_unhook_all) -{ - dXSARGS; - - /* make C compiler happy */ - (void) cv; - (void) items; - - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_perl_plugin, perl_current_script); - - API_RETURN_OK; -} - -/* - * weechat_perl_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_perl_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_perl_api_buffer_close_cb: callback for buffer closed - */ - -int -weechat_perl_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::buffer_new: create a new buffer - */ - -XS (XS_weechat_api_buffer_new) -{ - char *result, *name, *function_input, *data_input, *function_close; - char *data_close; - dXSARGS; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - if (items < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - function_input = SvPV_nolen (ST (1)); - data_input = SvPV_nolen (ST (2)); - function_close = SvPV_nolen (ST (3)); - data_close = SvPV_nolen (ST (4)); - - result = script_ptr2str (script_api_buffer_new (weechat_perl_plugin, - perl_current_script, - name, - &weechat_perl_api_buffer_input_data_cb, - function_input, - data_input, - &weechat_perl_api_buffer_close_cb, - function_close, - data_close)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::buffer_search: search a buffer - */ - -XS (XS_weechat_api_buffer_search) -{ - char *result, *plugin, *name; - dXSARGS; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - plugin = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_buffer_search (plugin, name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::buffer_search_main: search main buffer (WeeChat core buffer) - */ - -XS (XS_weechat_api_buffer_search_main) -{ - char *result; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::current_buffer: get current buffer - */ - -XS (XS_weechat_api_current_buffer) -{ - char *result; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::buffer_clear: clear a buffer - */ - -XS (XS_weechat_api_buffer_clear) -{ - dXSARGS; - - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_clear (API_STR2PTR(SvPV_nolen (ST (0)))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat::buffer_close: close a buffer - */ - -XS (XS_weechat_api_buffer_close) -{ - dXSARGS; - - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_buffer_close (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat::buffer_merge: merge a buffer to another buffer - */ - -XS (XS_weechat_api_buffer_merge) -{ - dXSARGS; - - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_merge (API_STR2PTR(SvPV_nolen (ST (0))), /* buffer */ - API_STR2PTR(SvPV_nolen (ST (1)))); /* target_buffer */ - - API_RETURN_OK; -} - -/* - * weechat::buffer_unmerge: unmerge a buffer from group of merged buffers - */ - -XS (XS_weechat_api_buffer_unmerge) -{ - dXSARGS; - - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_unmerge (API_STR2PTR(SvPV_nolen (ST (0))), /* buffer */ - SvIV (ST (1))); /* number */ - - API_RETURN_OK; -} - -/* - * weechat::buffer_get_integer: get a buffer property as integer - */ - -XS (XS_weechat_api_buffer_get_integer) -{ - char *buffer, *property; - int value; - dXSARGS; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - value = weechat_buffer_get_integer (API_STR2PTR(buffer), property); - - API_RETURN_INT(value); -} - -/* - * weechat::buffer_get_string: get a buffer property as string - */ - -XS (XS_weechat_api_buffer_get_string) -{ - char *buffer, *property; - const char *result; - dXSARGS; - - API_FUNC(1, "buffer_get_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = weechat_buffer_get_string (API_STR2PTR(buffer), property); - - API_RETURN_STRING(result); -} - -/* - * weechat::buffer_get_pointer: get a buffer property as pointer - */ - -XS (XS_weechat_api_buffer_get_pointer) -{ - char *result, *buffer, *property; - dXSARGS; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(buffer), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::buffer_set: set a buffer property - */ - -XS (XS_weechat_api_buffer_set) -{ - char *buffer, *property, *value; - dXSARGS; - - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - if (items < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - value = SvPV_nolen (ST (2)); - - weechat_buffer_set (API_STR2PTR(buffer), property, value); - - API_RETURN_OK; -} - -/* - * weechat::buffer_string_replace_local_var: replace local variables ($var) in a string, - * using value of local variables - */ - -XS (XS_weechat_api_buffer_string_replace_local_var) -{ - char *buffer, *string, *result; - dXSARGS; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - string = SvPV_nolen (ST (1)); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(buffer), string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::buffer_match_list: return 1 if buffer matches list of buffers - */ - -XS (XS_weechat_api_buffer_match_list) -{ - char *buffer, *string; - int value; - dXSARGS; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - buffer = SvPV_nolen (ST (0)); - string = SvPV_nolen (ST (1)); - - value = weechat_buffer_match_list (API_STR2PTR(buffer), string); - - API_RETURN_INT(value); -} - -/* - * weechat::current_window: get current window - */ - -XS (XS_weechat_api_current_window) -{ - char *result; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::window_search_with_buffer: search a window with buffer pointer - */ - -XS (XS_weechat_api_window_search_with_buffer) -{ - char *result; - dXSARGS; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(SvPV_nolen (ST (0))))); - - API_RETURN_STRING_FREE(result); -} - - -/* - * weechat::window_get_integer: get a window property as integer - */ - -XS (XS_weechat_api_window_get_integer) -{ - char *window, *property; - int value; - dXSARGS; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - window = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - value = weechat_window_get_integer (API_STR2PTR(window), property); - - API_RETURN_INT(value); -} - -/* - * weechat::window_get_string: get a window property as string - */ - -XS (XS_weechat_api_window_get_string) -{ - char *window, *property; - const char *result; - dXSARGS; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = weechat_window_get_string (API_STR2PTR(window), property); - - API_RETURN_STRING(result); -} - -/* - * weechat::window_get_pointer: get a window property as pointer - */ - -XS (XS_weechat_api_window_get_pointer) -{ - char *result, *window, *property; - dXSARGS; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(window), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::window_set_title: set window title - */ - -XS (XS_weechat_api_window_set_title) -{ - dXSARGS; - - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_window_set_title (SvPV_nolen (ST (0))); /* title */ - - API_RETURN_OK; -} - -/* - * weechat::nicklist_add_group: add a group in nicklist - */ - -XS (XS_weechat_api_nicklist_add_group) -{ - char *result, *buffer, *parent_group, *name, *color; - dXSARGS; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - if (items < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - parent_group = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - color = SvPV_nolen (ST (3)); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(buffer), - API_STR2PTR(parent_group), - name, - color, - SvIV (ST (4)))); /* visible */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_search_group: search a group in nicklist - */ - -XS (XS_weechat_api_nicklist_search_group) -{ - char *result, *buffer, *from_group, *name; - dXSARGS; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - from_group = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_add_nick: add a nick in nicklist - */ - -XS (XS_weechat_api_nicklist_add_nick) -{ - char *result, *buffer, *group, *name, *color, *prefix, *prefix_color; - dXSARGS; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - if (items < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - color = SvPV_nolen (ST (3)); - prefix = SvPV_nolen (ST (4)); - prefix_color = SvPV_nolen (ST (5)); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(buffer), - API_STR2PTR(group), - name, - color, - prefix, - prefix_color, - SvIV (ST (6)))); /* visible */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_search_nick: search a nick in nicklist - */ - -XS (XS_weechat_api_nicklist_search_nick) -{ - char *result, *buffer, *from_group, *name; - dXSARGS; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - from_group = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_remove_group: remove a group from nicklist - */ - -XS (XS_weechat_api_nicklist_remove_group) -{ - char *buffer, *group; - dXSARGS; - - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - - weechat_nicklist_remove_group (API_STR2PTR(buffer), - API_STR2PTR(group)); - - API_RETURN_OK; -} - -/* - * weechat::nicklist_remove_nick: remove a nick from nicklist - */ - -XS (XS_weechat_api_nicklist_remove_nick) -{ - char *buffer, *nick; - dXSARGS; - - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - nick = SvPV_nolen (ST (1)); - - weechat_nicklist_remove_nick (API_STR2PTR(buffer), - API_STR2PTR(nick)); - - API_RETURN_OK; -} - -/* - * weechat::nicklist_remove_all: remove all groups/nicks from nicklist - */ - -XS (XS_weechat_api_nicklist_remove_all) -{ - dXSARGS; - - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_all (API_STR2PTR(SvPV_nolen (ST (0)))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat::nicklist_group_get_integer: get a group property as integer - */ - -XS (XS_weechat_api_nicklist_group_get_integer) -{ - char *buffer, *group, *property; - int value; - dXSARGS; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - value = weechat_nicklist_group_get_integer (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_INT(value); -} - -/* - * weechat::nicklist_group_get_string: get a group property as string - */ - -XS (XS_weechat_api_nicklist_group_get_string) -{ - char *buffer, *group, *property; - const char *result; - dXSARGS; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - result = weechat_nicklist_group_get_string (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat::nicklist_group_get_pointer: get a group property as pointer - */ - -XS (XS_weechat_api_nicklist_group_get_pointer) -{ - char *result, *buffer, *group, *property; - dXSARGS; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(group), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_group_set: set a group property - */ - -XS (XS_weechat_api_nicklist_group_set) -{ - char *buffer, *group, *property, *value; - dXSARGS; - - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - group = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - value = SvPV_nolen (ST (3)); - - weechat_nicklist_group_set (API_STR2PTR(buffer), - API_STR2PTR(group), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat::nicklist_nick_get_integer: get a nick property as integer - */ - -XS (XS_weechat_api_nicklist_nick_get_integer) -{ - char *buffer, *nick, *property; - int value; - dXSARGS; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = SvPV_nolen (ST (0)); - nick = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - value = weechat_nicklist_nick_get_integer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_INT(value); -} - -/* - * weechat::nicklist_nick_get_string: get a nick property as string - */ - -XS (XS_weechat_api_nicklist_nick_get_string) -{ - char *buffer, *nick, *property; - const char *result; - dXSARGS; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - nick = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat::nicklist_nick_get_pointer: get a nick property as pointer - */ - -XS (XS_weechat_api_nicklist_nick_get_pointer) -{ - char *result, *buffer, *nick, *property; - dXSARGS; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = SvPV_nolen (ST (0)); - nick = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::nicklist_nick_set: set a nick property - */ - -XS (XS_weechat_api_nicklist_nick_set) -{ - char *buffer, *nick, *property, *value; - dXSARGS; - - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - nick = SvPV_nolen (ST (1)); - property = SvPV_nolen (ST (2)); - value = SvPV_nolen (ST (3)); - - weechat_nicklist_nick_set (API_STR2PTR(buffer), - API_STR2PTR(nick), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat::bar_item_search: search a bar item - */ - -XS (XS_weechat_api_bar_item_search) -{ - char *result; - dXSARGS; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_item_search (SvPV_nolen (ST (0)))); /* name */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_perl_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_perl_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat::bar_item_new: add a new bar item - */ - -XS (XS_weechat_api_bar_item_new) -{ - char *result, *name, *function, *data; - dXSARGS; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - result = script_ptr2str (script_api_bar_item_new (weechat_perl_plugin, - perl_current_script, - name, - &weechat_perl_api_bar_item_build_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::bar_item_update: update a bar item on screen - */ - -XS (XS_weechat_api_bar_item_update) -{ - dXSARGS; - - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_item_update (SvPV_nolen (ST (0))); /* name */ - - API_RETURN_OK; -} - -/* - * weechat::bar_item_remove: remove a bar item - */ - -XS (XS_weechat_api_bar_item_remove) -{ - dXSARGS; - - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_bar_item_remove (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(SvPV_nolen (ST (0)))); /* item */ - - API_RETURN_OK; -} - -/* - * weechat::bar_search: search a bar - */ - -XS (XS_weechat_api_bar_search) -{ - char *result; - dXSARGS; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_search (SvPV_nolen (ST (0)))); /* name */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::bar_new: add a new bar - */ - -XS (XS_weechat_api_bar_new) -{ - char *result, *name, *hidden, *priority, *type, *conditions, *position; - char *filling_top_bottom, *filling_left_right, *size, *size_max, *color_fg; - char *color_delim, *color_bg, *separator, *bar_items; - dXSARGS; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - if (items < 15) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - hidden = SvPV_nolen (ST (1)); - priority = SvPV_nolen (ST (2)); - type = SvPV_nolen (ST (3)); - conditions = SvPV_nolen (ST (4)); - position = SvPV_nolen (ST (5)); - filling_top_bottom = SvPV_nolen (ST (6)); - filling_left_right = SvPV_nolen (ST (7)); - size = SvPV_nolen (ST (8)); - size_max = SvPV_nolen (ST (9)); - color_fg = SvPV_nolen (ST (10)); - color_delim = SvPV_nolen (ST (11)); - color_bg = SvPV_nolen (ST (12)); - separator = SvPV_nolen (ST (13)); - bar_items = SvPV_nolen (ST (14)); - - result = script_ptr2str (weechat_bar_new (name, - hidden, - priority, - type, - conditions, - position, - filling_top_bottom, - filling_left_right, - size, - size_max, - color_fg, - color_delim, - color_bg, - separator, - bar_items)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::bar_set: set a bar property - */ - -XS (XS_weechat_api_bar_set) -{ - char *bar, *property, *value; - dXSARGS; - - API_FUNC(1, "bar_set", API_RETURN_ERROR); - if (items < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - bar = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - value = SvPV_nolen (ST (2)); - - weechat_bar_set (API_STR2PTR(bar), property, value); - - API_RETURN_OK; -} - -/* - * weechat::bar_update: update a bar on screen - */ - -XS (XS_weechat_api_bar_update) -{ - dXSARGS; - - API_FUNC(1, "bar_update", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_update (SvPV_nolen (ST (0))); /* name */ - - API_RETURN_OK; -} - -/* - * weechat::bar_remove: remove a bar - */ - -XS (XS_weechat_api_bar_remove) -{ - dXSARGS; - - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_remove (API_STR2PTR(SvPV_nolen (ST (0)))); /* bar */ - - API_RETURN_OK; -} - -/* - * weechat::command: execute a command on a buffer - */ - -XS (XS_weechat_api_command) -{ - char *buffer, *command; - dXSARGS; - - API_FUNC(1, "command", API_RETURN_ERROR); - if (items < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = SvPV_nolen (ST (0)); - command = SvPV_nolen (ST (1)); - - script_api_command (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(buffer), - command); - - API_RETURN_OK; -} - -/* - * weechat::info_get: get info (as string) - */ - -XS (XS_weechat_api_info_get) -{ - char *info_name, *arguments; - const char *result; - dXSARGS; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = SvPV_nolen (ST (0)); - arguments = SvPV_nolen (ST (1)); - - result = weechat_info_get (info_name, arguments); - - API_RETURN_STRING(result); -} - -/* - * weechat::info_get_hashtable: get info (as hashtable) - */ - -XS (XS_weechat_api_info_get_hashtable) -{ - char *info_name; - struct t_hashtable *hashtable, *result_hashtable; - HV *result_hash; - dXSARGS; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = SvPV_nolen (ST (0)); - hashtable = weechat_perl_hash_to_hashtable (ST (1), - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (info_name, hashtable); - result_hash = weechat_perl_hashtable_to_hash (result_hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - API_RETURN_OBJ(result_hash); -} - -/* - * weechat::infolist_new: create new infolist - */ - -XS (XS_weechat_api_infolist_new) -{ - char *result; - dXSARGS; - - /* make C compiler happy */ - (void) items; - (void) cv; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_new_item: create new item in infolist - */ - -XS (XS_weechat_api_infolist_new_item) -{ - char *infolist, *result; - dXSARGS; - - API_FUNC(1, "infolist_new_item", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(infolist))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_new_var_integer: create new integer variable in infolist - */ - -XS (XS_weechat_api_infolist_new_var_integer) -{ - char *infolist, *name, *result; - dXSARGS; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(infolist), - name, - SvIV (ST (2)))); /* value */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_new_var_string: create new string variable in infolist - */ - -XS (XS_weechat_api_infolist_new_var_string) -{ - char *infolist, *name, *value, *result; - dXSARGS; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - value = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_new_var_pointer: create new pointer variable in infolist - */ - -XS (XS_weechat_api_infolist_new_var_pointer) -{ - char *infolist, *name, *value, *result; - dXSARGS; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - value = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(infolist), - name, - API_STR2PTR(value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_new_var_time: create new time variable in infolist - */ - -XS (XS_weechat_api_infolist_new_var_time) -{ - char *infolist, *name, *result; - dXSARGS; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(infolist), - name, - SvIV (ST (2)))); /* value */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_get: get list with infos - */ - -XS (XS_weechat_api_infolist_get) -{ - char *result, *name, *pointer, *arguments; - dXSARGS; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - arguments = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_infolist_get (name, - API_STR2PTR(pointer), - arguments)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_next: move item pointer to next item in infolist - */ - -XS (XS_weechat_api_infolist_next) -{ - int value; - dXSARGS; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_next (API_STR2PTR(SvPV_nolen (ST (0)))); /* infolist */ - - API_RETURN_INT(value); -} - -/* - * weechat::infolist_prev: move item pointer to previous item in infolist - */ - -XS (XS_weechat_api_infolist_prev) -{ - int value; - dXSARGS; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - if (items < 1) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_prev (API_STR2PTR(SvPV_nolen (ST (0)))); /* infolist */ - - API_RETURN_INT(value); -} - -/* - * weechat::infolist_reset_item_cursor: reset pointer to current item in - * infolist - */ - -XS (XS_weechat_api_infolist_reset_item_cursor) -{ - dXSARGS; - - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_reset_item_cursor (API_STR2PTR(SvPV_nolen (ST (0)))); /* infolist */ - - API_RETURN_OK; -} - -/* - * weechat::infolist_fields: get list of fields for current item of infolist - */ - -XS (XS_weechat_api_infolist_fields) -{ - const char *result; - dXSARGS; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_fields (API_STR2PTR(SvPV_nolen (ST (0)))); /* infolist */ - - API_RETURN_STRING(result); -} - -/* - * weechat::infolist_integer: get integer value of a variable in infolist - */ - -XS (XS_weechat_api_infolist_integer) -{ - char *infolist, *variable; - int value; - dXSARGS; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - infolist = SvPV_nolen (ST (0)); - variable = SvPV_nolen (ST (1)); - - value = weechat_infolist_integer (API_STR2PTR(infolist), variable); - - API_RETURN_INT(value); -} - -/* - * weechat::infolist_string: get string value of a variable in infolist - */ - -XS (XS_weechat_api_infolist_string) -{ - char *infolist, *variable; - const char *result; - dXSARGS; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - variable = SvPV_nolen (ST (1)); - - result = weechat_infolist_string (API_STR2PTR(infolist), variable); - - API_RETURN_STRING(result); -} - -/* - * weechat::infolist_pointer: get pointer value of a variable in infolist - */ - -XS (XS_weechat_api_infolist_pointer) -{ - char *infolist, *variable; - char *result; - dXSARGS; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - variable = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(infolist), variable)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_time: get time value of a variable in infolist - */ - -XS (XS_weechat_api_infolist_time) -{ - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result, *infolist, *variable; - dXSARGS; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = SvPV_nolen (ST (0)); - variable = SvPV_nolen (ST (1)); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(infolist), variable); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::infolist_free: free infolist - */ - -XS (XS_weechat_api_infolist_free) -{ - dXSARGS; - - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_free (API_STR2PTR(SvPV_nolen (ST (0)))); /* infolist */ - - API_RETURN_OK; -} - -/* - * weechat::hdata_get: get hdata - */ - -XS (XS_weechat_api_hdata_get) -{ - char *result, *name; - dXSARGS; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - if (items < 1) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = SvPV_nolen (ST (0)); - - result = script_ptr2str (weechat_hdata_get (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hdata_get_var_offset: get offset of variable in hdata - */ - -XS (XS_weechat_api_hdata_get_var_offset) -{ - char *hdata, *name; - int value; - dXSARGS; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - if (items < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - value = weechat_hdata_get_var_offset (API_STR2PTR(hdata), name); - - API_RETURN_INT(value); -} - -/* - * weechat::hdata_get_var_type_string: get type of variable as string in hdata - */ - -XS (XS_weechat_api_hdata_get_var_type_string) -{ - const char *result; - char *hdata, *name; - dXSARGS; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat::hdata_get_var_array_size: get array size for variable in hdata - */ - -XS (XS_weechat_api_hdata_get_var_array_size) -{ - char *hdata, *pointer, *name; - int value; - dXSARGS; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - value = weechat_hdata_get_var_array_size (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat::hdata_get_var_array_size_string: get array size for variable in - * hdata (as string) - */ - -XS (XS_weechat_api_hdata_get_var_array_size_string) -{ - const char *result; - char *hdata, *pointer, *name; - dXSARGS; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat::hdata_get_var_hdata: get hdata for variable in hdata - */ - -XS (XS_weechat_api_hdata_get_var_hdata) -{ - const char *result; - char *hdata, *name; - dXSARGS; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat::hdata_get_list: get list pointer in hdata - */ - -XS (XS_weechat_api_hdata_get_list) -{ - char *hdata, *name; - char *result; - dXSARGS; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - name = SvPV_nolen (ST (1)); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(hdata), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hdata_check_pointer: check pointer with hdata/list - */ - -XS (XS_weechat_api_hdata_check_pointer) -{ - char *hdata, *list, *pointer; - int value; - dXSARGS; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = SvPV_nolen (ST (0)); - list = SvPV_nolen (ST (1)); - pointer = SvPV_nolen (ST (2)); - - value = weechat_hdata_check_pointer (API_STR2PTR(hdata), - API_STR2PTR(list), - API_STR2PTR(pointer)); - - API_RETURN_INT(value); -} - -/* - * weechat::hdata_move: move pointer to another element in list - */ - -XS (XS_weechat_api_hdata_move) -{ - char *result, *hdata, *pointer; - int count; - dXSARGS; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - count = SvIV(ST (2)); - - result = script_ptr2str (weechat_hdata_move (API_STR2PTR(hdata), - API_STR2PTR(pointer), - count)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hdata_char: get char value of a variable in structure using hdata - */ - -XS (XS_weechat_api_hdata_char) -{ - char *hdata, *pointer, *name; - int value; - dXSARGS; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - value = (int)weechat_hdata_char (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat::hdata_integer: get integer value of a variable in structure using - * hdata - */ - -XS (XS_weechat_api_hdata_integer) -{ - char *hdata, *pointer, *name; - int value; - dXSARGS; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - value = weechat_hdata_integer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat::hdata_long: get long value of a variable in structure using hdata - */ - -XS (XS_weechat_api_hdata_long) -{ - char *hdata, *pointer, *name; - long value; - dXSARGS; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - value = weechat_hdata_long (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_LONG(value); -} - -/* - * weechat::hdata_string: get string value of a variable in structure using - * hdata - */ - -XS (XS_weechat_api_hdata_string) -{ - char *hdata, *pointer, *name; - const char *result; - dXSARGS; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result = weechat_hdata_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat::hdata_pointer: get pointer value of a variable in structure using - * hdata - */ - -XS (XS_weechat_api_hdata_pointer) -{ - char *hdata, *pointer, *name; - char *result; - dXSARGS; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hdata_time: get time value of a variable in structure using hdata - */ - -XS (XS_weechat_api_hdata_time) -{ - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result, *hdata, *pointer, *name; - dXSARGS; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::hdata_hashtable: get hashtable value of a variable in structure - * using hdata - */ - -XS (XS_weechat_api_hdata_hashtable) -{ - char *hdata, *pointer, *name; - HV *result_hash; - dXSARGS; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - if (items < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - pointer = SvPV_nolen (ST (1)); - name = SvPV_nolen (ST (2)); - - result_hash = weechat_perl_hashtable_to_hash ( - weechat_hdata_hashtable (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_OBJ(result_hash); -} - -/* - * weechat::hdata_get_string: get hdata property as string - */ - -XS (XS_weechat_api_hdata_get_string) -{ - char *hdata, *property; - const char *result; - dXSARGS; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = weechat_hdata_get_string (API_STR2PTR(hdata), property); - - API_RETURN_STRING(result); -} - -/* - * weechat::upgrade_new: create an upgrade file - */ - -XS (XS_weechat_api_upgrade_new) -{ - char *result, *filename; - dXSARGS; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - filename = SvPV_nolen (ST (0)); - - result = script_ptr2str (weechat_upgrade_new (filename, - SvIV (ST (1)))); /* write */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat::upgrade_write_object: write object in upgrade file - */ - -XS (XS_weechat_api_upgrade_write_object) -{ - char *upgrade_file, *infolist; - int rc; - dXSARGS; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - upgrade_file = SvPV_nolen (ST (0)); - infolist = SvPV_nolen (ST (2)); - - rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file), - SvIV (ST (1)), /* object_id */ - API_STR2PTR(infolist)); - - API_RETURN_INT(rc); -} - -/* - * weechat_perl_api_upgrade_read_cb: callback for reading object in upgrade file - */ - -int -weechat_perl_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_perl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat::config_upgrade_read: read upgrade file - */ - -XS (XS_weechat_api_upgrade_read) -{ - char *upgrade_file, *function, *data; - int rc; - dXSARGS; - - API_FUNC(1, "upgrade_read", API_RETURN_INT(0)); - if (items < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - upgrade_file = SvPV_nolen (ST (0)); - function = SvPV_nolen (ST (1)); - data = SvPV_nolen (ST (2)); - - rc = script_api_upgrade_read (weechat_perl_plugin, - perl_current_script, - API_STR2PTR(upgrade_file), - &weechat_perl_api_upgrade_read_cb, - function, - data); - - API_RETURN_INT(rc); -} - -/* - * weechat::upgrade_close: close upgrade file - */ - -XS (XS_weechat_api_upgrade_close) -{ - char *upgrade_file; - dXSARGS; - - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - if (items < 1) - API_WRONG_ARGS(API_RETURN_ERROR); - - upgrade_file = SvPV_nolen (ST (0)); - - weechat_upgrade_close (API_STR2PTR(upgrade_file)); - - API_RETURN_OK; -} - -/* - * weechat_perl_api_init: initialize subroutines - */ - -void -weechat_perl_api_init (pTHX) -{ - HV *stash; - - newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); - - /* interface functions */ - API_DEF_FUNC(register); - API_DEF_FUNC(plugin_get_name); - API_DEF_FUNC(charset_set); - API_DEF_FUNC(iconv_to_internal); - API_DEF_FUNC(iconv_from_internal); - API_DEF_FUNC(gettext); - API_DEF_FUNC(ngettext); - API_DEF_FUNC(string_match); - API_DEF_FUNC(string_has_highlight); - API_DEF_FUNC(string_has_highlight_regex); - API_DEF_FUNC(string_mask_to_regex); - API_DEF_FUNC(string_remove_color); - API_DEF_FUNC(string_is_command_char); - API_DEF_FUNC(string_input_for_buffer); - API_DEF_FUNC(mkdir_home); - API_DEF_FUNC(mkdir); - API_DEF_FUNC(mkdir_parents); - API_DEF_FUNC(list_new); - API_DEF_FUNC(list_add); - API_DEF_FUNC(list_search); - API_DEF_FUNC(list_search_pos); - API_DEF_FUNC(list_casesearch); - API_DEF_FUNC(list_casesearch_pos); - API_DEF_FUNC(list_get); - API_DEF_FUNC(list_set); - API_DEF_FUNC(list_next); - API_DEF_FUNC(list_prev); - API_DEF_FUNC(list_string); - API_DEF_FUNC(list_size); - API_DEF_FUNC(list_remove); - API_DEF_FUNC(list_remove_all); - API_DEF_FUNC(list_free); - API_DEF_FUNC(config_new); - API_DEF_FUNC(config_new_section); - API_DEF_FUNC(config_search_section); - API_DEF_FUNC(config_new_option); - API_DEF_FUNC(config_search_option); - API_DEF_FUNC(config_string_to_boolean); - API_DEF_FUNC(config_option_reset); - API_DEF_FUNC(config_option_set); - API_DEF_FUNC(config_option_set_null); - API_DEF_FUNC(config_option_unset); - API_DEF_FUNC(config_option_rename); - API_DEF_FUNC(config_option_is_null); - API_DEF_FUNC(config_option_default_is_null); - API_DEF_FUNC(config_boolean); - API_DEF_FUNC(config_boolean_default); - API_DEF_FUNC(config_integer); - API_DEF_FUNC(config_integer_default); - API_DEF_FUNC(config_string); - API_DEF_FUNC(config_string_default); - API_DEF_FUNC(config_color); - API_DEF_FUNC(config_color_default); - API_DEF_FUNC(config_write_option); - API_DEF_FUNC(config_write_line); - API_DEF_FUNC(config_write); - API_DEF_FUNC(config_read); - API_DEF_FUNC(config_reload); - API_DEF_FUNC(config_option_free); - API_DEF_FUNC(config_section_free_options); - API_DEF_FUNC(config_section_free); - API_DEF_FUNC(config_free); - API_DEF_FUNC(config_get); - API_DEF_FUNC(config_get_plugin); - API_DEF_FUNC(config_is_set_plugin); - API_DEF_FUNC(config_set_plugin); - API_DEF_FUNC(config_set_desc_plugin); - API_DEF_FUNC(config_unset_plugin); - API_DEF_FUNC(key_bind); - API_DEF_FUNC(key_unbind); - API_DEF_FUNC(prefix); - API_DEF_FUNC(color); - API_DEF_FUNC(print); - API_DEF_FUNC(print_date_tags); - API_DEF_FUNC(print_y); - API_DEF_FUNC(log_print); - API_DEF_FUNC(hook_command); - API_DEF_FUNC(hook_command_run); - API_DEF_FUNC(hook_timer); - API_DEF_FUNC(hook_fd); - API_DEF_FUNC(hook_process); - API_DEF_FUNC(hook_process_hashtable); - API_DEF_FUNC(hook_connect); - API_DEF_FUNC(hook_print); - API_DEF_FUNC(hook_signal); - API_DEF_FUNC(hook_signal_send); - API_DEF_FUNC(hook_hsignal); - API_DEF_FUNC(hook_hsignal_send); - API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_list_add); - API_DEF_FUNC(hook_modifier); - API_DEF_FUNC(hook_modifier_exec); - API_DEF_FUNC(hook_info); - API_DEF_FUNC(hook_info_hashtable); - API_DEF_FUNC(hook_infolist); - API_DEF_FUNC(hook_focus); - API_DEF_FUNC(unhook); - API_DEF_FUNC(unhook_all); - API_DEF_FUNC(buffer_new); - API_DEF_FUNC(buffer_search); - API_DEF_FUNC(buffer_search_main); - API_DEF_FUNC(current_buffer); - API_DEF_FUNC(buffer_clear); - API_DEF_FUNC(buffer_close); - API_DEF_FUNC(buffer_merge); - API_DEF_FUNC(buffer_unmerge); - API_DEF_FUNC(buffer_get_integer); - API_DEF_FUNC(buffer_get_string); - API_DEF_FUNC(buffer_get_pointer); - API_DEF_FUNC(buffer_set); - API_DEF_FUNC(buffer_string_replace_local_var); - API_DEF_FUNC(buffer_match_list); - API_DEF_FUNC(current_window); - API_DEF_FUNC(window_search_with_buffer); - API_DEF_FUNC(window_get_integer); - API_DEF_FUNC(window_get_string); - API_DEF_FUNC(window_get_pointer); - API_DEF_FUNC(window_set_title); - API_DEF_FUNC(nicklist_add_group); - API_DEF_FUNC(nicklist_search_group); - API_DEF_FUNC(nicklist_add_nick); - API_DEF_FUNC(nicklist_search_nick); - API_DEF_FUNC(nicklist_remove_group); - API_DEF_FUNC(nicklist_remove_nick); - API_DEF_FUNC(nicklist_remove_all); - API_DEF_FUNC(nicklist_group_get_integer); - API_DEF_FUNC(nicklist_group_get_string); - API_DEF_FUNC(nicklist_group_get_pointer); - API_DEF_FUNC(nicklist_group_set); - API_DEF_FUNC(nicklist_nick_get_integer); - API_DEF_FUNC(nicklist_nick_get_string); - API_DEF_FUNC(nicklist_nick_get_pointer); - API_DEF_FUNC(nicklist_nick_set); - API_DEF_FUNC(bar_item_search); - API_DEF_FUNC(bar_item_new); - API_DEF_FUNC(bar_item_update); - API_DEF_FUNC(bar_item_remove); - API_DEF_FUNC(bar_search); - API_DEF_FUNC(bar_new); - API_DEF_FUNC(bar_set); - API_DEF_FUNC(bar_update); - API_DEF_FUNC(bar_remove); - API_DEF_FUNC(command); - API_DEF_FUNC(info_get); - API_DEF_FUNC(info_get_hashtable); - API_DEF_FUNC(infolist_new); - API_DEF_FUNC(infolist_new_item); - API_DEF_FUNC(infolist_new_var_integer); - API_DEF_FUNC(infolist_new_var_string); - API_DEF_FUNC(infolist_new_var_pointer); - API_DEF_FUNC(infolist_new_var_time); - API_DEF_FUNC(infolist_get); - API_DEF_FUNC(infolist_next); - API_DEF_FUNC(infolist_prev); - API_DEF_FUNC(infolist_reset_item_cursor); - API_DEF_FUNC(infolist_fields); - API_DEF_FUNC(infolist_integer); - API_DEF_FUNC(infolist_string); - API_DEF_FUNC(infolist_pointer); - API_DEF_FUNC(infolist_time); - API_DEF_FUNC(infolist_free); - API_DEF_FUNC(hdata_get); - API_DEF_FUNC(hdata_get_var_offset); - API_DEF_FUNC(hdata_get_var_type_string); - API_DEF_FUNC(hdata_get_var_array_size); - API_DEF_FUNC(hdata_get_var_array_size_string); - API_DEF_FUNC(hdata_get_var_hdata); - API_DEF_FUNC(hdata_get_list); - API_DEF_FUNC(hdata_check_pointer); - API_DEF_FUNC(hdata_move); - API_DEF_FUNC(hdata_char); - API_DEF_FUNC(hdata_integer); - API_DEF_FUNC(hdata_long); - API_DEF_FUNC(hdata_string); - API_DEF_FUNC(hdata_pointer); - API_DEF_FUNC(hdata_time); - API_DEF_FUNC(hdata_hashtable); - API_DEF_FUNC(hdata_get_string); - API_DEF_FUNC(upgrade_new); - API_DEF_FUNC(upgrade_write_object); - API_DEF_FUNC(upgrade_read); - API_DEF_FUNC(upgrade_close); - - /* interface constants */ - stash = gv_stashpv ("weechat", TRUE); - newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK)); - newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_EAT", newSViv (WEECHAT_RC_OK_EAT)); - newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR)); - - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_READ_OK", newSViv (WEECHAT_CONFIG_READ_OK)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_READ_MEMORY_ERROR", newSViv (WEECHAT_CONFIG_READ_MEMORY_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_READ_FILE_NOT_FOUND", newSViv (WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_WRITE_OK", newSViv (WEECHAT_CONFIG_WRITE_OK)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_WRITE_ERROR", newSViv (WEECHAT_CONFIG_WRITE_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_WRITE_MEMORY_ERROR", newSViv (WEECHAT_CONFIG_WRITE_MEMORY_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", newSViv (WEECHAT_CONFIG_OPTION_SET_OK_CHANGED)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", newSViv (WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_SET_ERROR", newSViv (WEECHAT_CONFIG_OPTION_SET_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", newSViv (WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", newSViv (WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", newSViv (WEECHAT_CONFIG_OPTION_UNSET_OK_RESET)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", newSViv (WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)); - newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_OPTION_UNSET_ERROR", newSViv (WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_SORT", newSVpv (WEECHAT_LIST_POS_SORT, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_BEGINNING", newSVpv (WEECHAT_LIST_POS_BEGINNING, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_END", newSVpv (WEECHAT_LIST_POS_END, PL_na)); - - newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_LOW", newSVpv (WEECHAT_HOTLIST_LOW, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_MESSAGE", newSVpv (WEECHAT_HOTLIST_MESSAGE, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_PRIVATE", newSVpv (WEECHAT_HOTLIST_PRIVATE, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_HOTLIST_HIGHLIGHT", newSVpv (WEECHAT_HOTLIST_HIGHLIGHT, PL_na)); - - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_PROCESS_RUNNING", newSViv (WEECHAT_HOOK_PROCESS_RUNNING)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_PROCESS_ERROR", newSViv (WEECHAT_HOOK_PROCESS_ERROR)); - - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_OK", newSViv (WEECHAT_HOOK_CONNECT_OK)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", newSViv (WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", newSViv (WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", newSViv (WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_PROXY_ERROR", newSViv (WEECHAT_HOOK_CONNECT_PROXY_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", newSViv (WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", newSViv (WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", newSViv (WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_MEMORY_ERROR", newSViv (WEECHAT_HOOK_CONNECT_MEMORY_ERROR)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_CONNECT_TIMEOUT", newSViv (WEECHAT_HOOK_CONNECT_TIMEOUT)); - - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_STRING", newSVpv (WEECHAT_HOOK_SIGNAL_STRING, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_INT", newSVpv (WEECHAT_HOOK_SIGNAL_INT, PL_na)); - newCONSTSUB (stash, "weechat::WEECHAT_HOOK_SIGNAL_POINTER", newSVpv (WEECHAT_HOOK_SIGNAL_POINTER, PL_na)); -} diff --git a/src/plugins/scripts/perl/weechat-perl-api.h b/src/plugins/scripts/perl/weechat-perl-api.h deleted file mode 100644 index 662dd002a..000000000 --- a/src/plugins/scripts/perl/weechat-perl-api.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_PERL_API_H -#define __WEECHAT_PERL_API_H 1 - -extern int weechat_perl_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_perl_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); -extern void weechat_perl_api_init (pTHX); - -#endif /* __WEECHAT_PERL_API_H */ diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c deleted file mode 100644 index 0acf76651..000000000 --- a/src/plugins/scripts/perl/weechat-perl.c +++ /dev/null @@ -1,1029 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2008 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-perl.c: perl plugin for WeeChat - */ - -#undef _ - -#include <EXTERN.h> -#include <perl.h> -#include <XSUB.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-perl.h" -#include "weechat-perl-api.h" - - -WEECHAT_PLUGIN_NAME(PERL_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of perl scripts")); -WEECHAT_PLUGIN_AUTHOR("Sebastien Helleu <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_perl_plugin = NULL; - -int perl_quiet = 0; -struct t_plugin_script *perl_scripts = NULL; -struct t_plugin_script *last_perl_script = NULL; -struct t_plugin_script *perl_current_script = NULL; -struct t_plugin_script *perl_registered_script = NULL; -const char *perl_current_script_filename = NULL; -int perl_quit_or_upgrade = 0; - -/* - * string used to execute action "install": - * when signal "perl_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *perl_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "perl_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *perl_action_remove_list = NULL; - -#ifdef NO_PERL_MULTIPLICITY -#undef MULTIPLICITY -#endif - -#ifndef MULTIPLICITY -#define PKG_NAME_PREFIX "WeechatPerlPackage" -static PerlInterpreter *perl_main = NULL; -int perl_num = 0; -#endif - -char *perl_args[] = { "", "-e", "0", "-w", NULL }; -int perl_args_count = 4; - -char *perl_weechat_code = -{ -#ifndef MULTIPLICITY - "package WeechatPerlScriptLoader;" -#endif - "$weechat_perl_load_eval_file_error = \"\";" - "sub weechat_perl_load_file" - "{" - " my $filename = shift;" - " local $/ = undef;" - " open FILE, $filename or return \"__WEECHAT_PERL_ERROR__\";" - " $_ = <FILE>;" - " close FILE;" - " return $_;" - "}" - "sub weechat_perl_load_eval_file" - "{" -#ifdef MULTIPLICITY - " my $filename = shift;" -#else - " my ($filename, $package) = @_;" -#endif - " my $content = weechat_perl_load_file ($filename);" - " if ($content eq \"__WEECHAT_PERL_ERROR__\")" - " {" - " return 1;" - " }" -#ifdef MULTIPLICITY - " my $eval = $content;" -#else - " my $eval = qq{package $package; $content;};" -#endif - " {" - " eval $eval;" - " }" - " if ($@)" - " {" - " $weechat_perl_load_eval_file_error = $@;" - " return 2;" - " }" - " return 0;" - "}" - "$SIG{__WARN__} = sub { weechat::print(\"\", \"\tperl error: $_[0]\"); };" - "$SIG{__DIE__} = sub { weechat::print(\"\", \"\tperl error: $_[0]\"); };" -}; - - -/* - * weechat_perl_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_perl_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - HV *hash; - - /* make C compiler happy */ - (void) hashtable; - - hash = (HV *)data; - - (void) hv_store (hash, key, strlen (key), newSVpv (value, 0), 0); -} - -/* - * weechat_perl_hashtable_to_hash: get perl hash with a WeeChat hashtable - */ - -HV * -weechat_perl_hashtable_to_hash (struct t_hashtable *hashtable) -{ - HV *hash; - - hash = (HV *)newHV (); - if (!hash) - return NULL; - - weechat_hashtable_map_string (hashtable, - &weechat_perl_hashtable_map_cb, - hash); - - return hash; -} - -/* - * weechat_perl_hash_to_hashtable: get WeeChat hashtable with perl hash - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after use - * with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size) -{ - struct t_hashtable *hashtable; - HV *hash2; - SV *value; - char *str_key; - I32 retlen; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - if ((hash) && SvROK(hash) && SvRV(hash) && (SvTYPE(SvRV(hash)) == SVt_PVHV)) - { - hash2 = (HV *) SvRV(hash); - hv_iterinit (hash2); - while ((value = hv_iternextsv (hash2, &str_key, &retlen))) - { - weechat_hashtable_set (hashtable, str_key, SvPV (value, PL_na)); - } - } - - return hashtable; -} - -/* - * weechat_perl_exec: execute a perl function - */ - -void * -weechat_perl_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv) -{ - char *func; - unsigned int count; - void *ret_value; - int *ret_i, mem_err, length, i, argc; - SV *ret_s; - HV *hash; - struct t_plugin_script *old_perl_current_script; -#ifdef MULTIPLICITY - void *old_context; -#endif - - old_perl_current_script = perl_current_script; - perl_current_script = script; - -#ifdef MULTIPLICITY - (void) length; - func = (char *) function; - old_context = PERL_GET_CONTEXT; - if (script->interpreter) - PERL_SET_CONTEXT (script->interpreter); -#else - length = strlen ((script->interpreter) ? script->interpreter : perl_main) + - strlen (function) + 3; - func = (char *) malloc (length); - if (!func) - return NULL; - snprintf (func, length, "%s::%s", - (char *) ((script->interpreter) ? script->interpreter : perl_main), - function); -#endif - - dSP; - ENTER; - SAVETMPS; - - PUSHMARK(SP); - if (format && format[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - XPUSHs(sv_2mortal(newSVpv((char *)argv[i], 0))); - break; - case 'i': /* integer */ - XPUSHs(sv_2mortal(newSViv(*((int *)argv[i])))); - break; - case 'h': /* hash */ - hash = weechat_perl_hashtable_to_hash (argv[i]); - XPUSHs(sv_2mortal(newRV_inc((SV *)hash))); - break; - } - } - } - PUTBACK; - count = perl_call_pv (func, G_EVAL | G_SCALAR); - - ret_value = NULL; - mem_err = 1; - - SPAGAIN; - - if (SvTRUE (ERRSV)) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - SvPV_nolen (ERRSV)); - (void) POPs; /* poping the 'undef' */ - mem_err = 0; - } - else - { - if (count != 1) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" must " - "return one valid value (%d)"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - function, count); - mem_err = 0; - } - else - { - if (ret_type == WEECHAT_SCRIPT_EXEC_STRING) - { - ret_s = newSVsv(POPs); - ret_value = strdup (SvPV_nolen (ret_s)); - SvREFCNT_dec (ret_s); - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_INT) - { - ret_i = malloc (sizeof (*ret_i)); - if (ret_i) - *ret_i = POPi; - ret_value = ret_i; - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_value = weechat_perl_hash_to_hashtable (POPs, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" is " - "internally misused"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - function); - mem_err = 0; - } - } - } - - PUTBACK; - FREETMPS; - LEAVE; - - perl_current_script = old_perl_current_script; -#ifdef MULTIPLICITY - PERL_SET_CONTEXT (old_context); -#else - free (func); -#endif - - if (!ret_value && (mem_err == 1)) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: not enough memory in function " - "\"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, function); - return NULL; - } - - return ret_value; -} - -/* - * weechat_perl_load: load a Perl script - */ - -int -weechat_perl_load (const char *filename) -{ - STRLEN len; - struct t_plugin_script temp_script; - int *eval; - struct stat buf; - void *perl_argv[2]; - -#ifdef MULTIPLICITY - PerlInterpreter *perl_current_interpreter; -#else - char pkgname[64]; -#endif - - temp_script.filename = NULL; - temp_script.interpreter = NULL; - temp_script.name = NULL; - temp_script.author = NULL; - temp_script.version = NULL; - temp_script.license = NULL; - temp_script.description = NULL; - temp_script.shutdown_func = NULL; - temp_script.charset = NULL; - - if (stat (filename, &buf) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not found"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, filename); - return 0; - } - - if ((weechat_perl_plugin->debug >= 2) || !perl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - PERL_PLUGIN_NAME, filename); - } - - perl_current_script = NULL; - perl_current_script_filename = filename; - perl_registered_script = NULL; - -#ifdef MULTIPLICITY - perl_current_interpreter = perl_alloc(); - - if (!perl_current_interpreter) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to create new " - "sub-interpreter"), - weechat_prefix ("error"), PERL_PLUGIN_NAME); - return 0; - } - - PERL_SET_CONTEXT (perl_current_interpreter); - perl_construct (perl_current_interpreter); - temp_script.interpreter = (PerlInterpreter *) perl_current_interpreter; - perl_parse (perl_current_interpreter, weechat_perl_api_init, - perl_args_count, perl_args, NULL); - - eval_pv (perl_weechat_code, TRUE); - perl_argv[0] = (void *)filename; - eval = weechat_perl_exec (&temp_script, - WEECHAT_SCRIPT_EXEC_INT, - "weechat_perl_load_eval_file", - "s", perl_argv); -#else - snprintf (pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num); - perl_num++; - temp_script.interpreter = "WeechatPerlScriptLoader"; - perl_argv[0] = (void *)filename; - perl_argv[1] = pkgname; - eval = weechat_perl_exec (&temp_script, - WEECHAT_SCRIPT_EXEC_INT, - "weechat_perl_load_eval_file", - "ss", perl_argv); -#endif - if (!eval) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: not enough memory to parse " - "file \"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, filename); - return 0; - } - - if (*eval != 0) - { - if (*eval == 2) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to parse file " - "\"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - filename); -#ifdef MULTIPLICITY - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - SvPV(perl_get_sv("weechat_perl_load_eval_file_error", - FALSE), len)); -#else - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - SvPV(perl_get_sv("WeechatPerlScriptLoader::" - "weechat_perl_load_eval_file_error", - FALSE), len)); -#endif - } - else if (*eval == 1) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to run file \"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - filename); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown error while " - "loading file \"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - filename); - } -#ifdef MULTIPLICITY - perl_destruct (perl_current_interpreter); - perl_free (perl_current_interpreter); -#endif - if (perl_current_script && (perl_current_script != &temp_script)) - { - script_remove (weechat_perl_plugin, - &perl_scripts, &last_perl_script, - perl_current_script); - } - - free (eval); - return 0; - } - - free (eval); - - if (!perl_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, filename); -#ifdef MULTIPLICITY - perl_destruct (perl_current_interpreter); - perl_free (perl_current_interpreter); -#endif - return 0; - } - perl_current_script = perl_registered_script; - -#ifdef MULTIPLICITY - perl_current_script->interpreter = (PerlInterpreter *)perl_current_interpreter; -#else - perl_current_script->interpreter = strdup (pkgname); -#endif - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_perl_plugin, - perl_scripts, - perl_current_script, - &weechat_perl_api_buffer_input_data_cb, - &weechat_perl_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_perl_load_cb: callback for weechat_script_auto_load() function - */ - -void -weechat_perl_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_perl_load (filename); -} - -/* - * weechat_perl_unload: unload a Perl script - */ - -void -weechat_perl_unload (struct t_plugin_script *script) -{ - int *rc; - void *interpreter; - - if ((weechat_perl_plugin->debug >= 2) || !perl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - PERL_PLUGIN_NAME, script->name); - } - -#ifdef MULTIPLICITY - PERL_SET_CONTEXT (script->interpreter); -#else - eval_pv (script->interpreter, TRUE); -#endif - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *)weechat_perl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, - NULL, NULL); - if (rc) - free (rc); - } - - interpreter = script->interpreter; - - if (perl_current_script == script) - perl_current_script = (perl_current_script->prev_script) ? - perl_current_script->prev_script : perl_current_script->next_script; - - script_remove (weechat_perl_plugin, &perl_scripts, &last_perl_script, - script); - -#ifdef MULTIPLICITY - if (interpreter) - { - perl_destruct (interpreter); - perl_free (interpreter); - } -#else - if (interpreter) - free (interpreter); -#endif -} - -/* - * weechat_perl_unload_name: unload a Perl script by name - */ - -void -weechat_perl_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_perl_plugin, perl_scripts, name); - if (ptr_script) - { - weechat_perl_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - PERL_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, name); - } -} - -/* - * weechat_perl_unload_all: unload all Perl scripts - */ - -void -weechat_perl_unload_all () -{ - while (perl_scripts) - { - weechat_perl_unload (perl_scripts); - } -} - -/* - * weechat_perl_reload_name: reload a Perl script by name - */ - -void -weechat_perl_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_perl_plugin, perl_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_perl_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - PERL_PLUGIN_NAME, name); - weechat_perl_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, name); - } -} - -/* - * weechat_perl_command_cb: callback for "/perl" command - */ - -int -weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_perl_plugin, perl_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_perl_plugin, perl_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_perl_plugin, perl_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_perl_plugin, &weechat_perl_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_perl_unload_all (); - script_auto_load (weechat_perl_plugin, &weechat_perl_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_perl_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_perl_plugin, perl_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_perl_plugin, perl_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Perl script */ - path_script = script_search_path (weechat_perl_plugin, - argv_eol[2]); - weechat_perl_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Perl script */ - weechat_perl_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Perl script */ - weechat_perl_unload_name (argv_eol[2]); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), PERL_PLUGIN_NAME, "perl"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_completion_cb: callback for script completion - */ - -int -weechat_perl_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_perl_plugin, completion, perl_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_perl_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "perl_script") == 0) - { - return script_infolist_list_scripts (weechat_perl_plugin, - perl_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_perl_signal_debug_dump_cb: dump Perl plugin data in WeeChat log file - */ - -int -weechat_perl_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, PERL_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_perl_plugin, perl_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_signal_buffer_closed_cb: callback called when a buffer is closed - */ - -int -weechat_perl_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (perl_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_timer_action_cb: timer for executing actions - */ - -int -weechat_perl_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &perl_action_install_list) - { - script_action_install (weechat_perl_plugin, - perl_scripts, - &weechat_perl_unload, - &weechat_perl_load, - &perl_action_install_list); - } - else if (data == &perl_action_remove_list) - { - script_action_remove (weechat_perl_plugin, - perl_scripts, - &weechat_perl_unload, - &perl_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_perl_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "perl_script_install") == 0) - { - script_action_add (&perl_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_perl_timer_action_cb, - &perl_action_install_list); - } - else if (strcmp (signal, "perl_script_remove") == 0) - { - script_action_add (&perl_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_perl_timer_action_cb, - &perl_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_perl_signal_quit_upgrade_cb: callback called when exiting or - * upgrading WeeChat - */ - -int -weechat_perl_signal_quit_upgrade_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - (void) signal_data; - - perl_quit_or_upgrade = 1; - - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_init: initialize Perl plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; -#ifdef PERL_SYS_INIT3 - int a; - char **perl_args_local; - char *perl_env[] = {}; -#endif -#ifdef PERL_SYS_INIT3 - a = perl_args_count; - perl_args_local = perl_args; - (void) perl_env; - PERL_SYS_INIT3 (&a, (char ***)&perl_args_local, (char ***)&perl_env); -#endif - - weechat_perl_plugin = plugin; - -#ifndef MULTIPLICITY - perl_main = perl_alloc (); - - if (!perl_main) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to initialize %s"), - weechat_prefix ("error"), PERL_PLUGIN_NAME, - PERL_PLUGIN_NAME); - return WEECHAT_RC_ERROR; - } - - perl_construct (perl_main); - perl_parse (perl_main, weechat_perl_api_init, perl_args_count, - perl_args, NULL); - eval_pv (perl_weechat_code, TRUE); -#endif - - init.callback_command = &weechat_perl_command_cb; - init.callback_completion = &weechat_perl_completion_cb; - init.callback_infolist = &weechat_perl_infolist_cb; - init.callback_signal_debug_dump = &weechat_perl_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_perl_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_perl_signal_script_action_cb; - init.callback_load_file = &weechat_perl_load_cb; - - perl_quiet = 1; - script_init (weechat_perl_plugin, argc, argv, &init); - perl_quiet = 0; - - script_display_short_list (weechat_perl_plugin, - perl_scripts); - - weechat_hook_signal ("quit", &weechat_perl_signal_quit_upgrade_cb, NULL); - weechat_hook_signal ("upgrade", &weechat_perl_signal_quit_upgrade_cb, NULL); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: end Perl plugin - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - perl_quiet = 1; - script_end (plugin, &perl_scripts, &weechat_perl_unload_all); - perl_quiet = 0; - -#ifndef MULTIPLICITY - /* free perl intepreter */ - if (perl_main) - { - perl_destruct (perl_main); - perl_free (perl_main); - perl_main = NULL; - } -#endif - -#if defined(PERL_SYS_TERM) && !defined(__FreeBSD__) && !defined(WIN32) && !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__)) - /* - * we call this function on all OS, but NOT on FreeBSD or Cygwin, - * because it crashes with no reason (bug in Perl?) - */ - if (perl_quit_or_upgrade) - PERL_SYS_TERM (); -#endif - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/perl/weechat-perl.h b/src/plugins/scripts/perl/weechat-perl.h deleted file mode 100644 index 87a601aac..000000000 --- a/src/plugins/scripts/perl/weechat-perl.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_PERL_H -#define __WEECHAT_PERL_H 1 - -#define weechat_plugin weechat_perl_plugin -#define PERL_PLUGIN_NAME "perl" - -#define PERL_CURRENT_SCRIPT_NAME ((perl_current_script) ? perl_current_script->name : "-") - -extern struct t_weechat_plugin *weechat_perl_plugin; - -extern int perl_quiet; -extern struct t_plugin_script *perl_scripts; -extern struct t_plugin_script *last_perl_script; -extern struct t_plugin_script *perl_current_script; -extern struct t_plugin_script *perl_registered_script; -extern const char *perl_current_script_filename; - -extern HV *weechat_perl_hashtable_to_hash (struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_perl_hash_to_hashtable (SV *hash, - int hashtable_size); -extern void *weechat_perl_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv); - -#endif /* __WEECHAT_PERL_H */ diff --git a/src/plugins/scripts/python/CMakeLists.txt b/src/plugins/scripts/python/CMakeLists.txt deleted file mode 100644 index b39a5f394..000000000 --- a/src/plugins/scripts/python/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(python MODULE weechat-python.c weechat-python.h -weechat-python-api.c weechat-python-api.h) - -SET_TARGET_PROPERTIES(python PROPERTIES PREFIX "") - -IF(PYTHON_FOUND) - INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PYTHON_LFLAGS}") - TARGET_LINK_LIBRARIES(python ${PYTHON_LIBRARY} weechat_scripts) -ENDIF(PYTHON_FOUND) - -INSTALL(TARGETS python LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/python/Makefile.am b/src/plugins/scripts/python/Makefile.am deleted file mode 100644 index db37e7095..000000000 --- a/src/plugins/scripts/python/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(PYTHON_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = python.la - -python_la_SOURCES = weechat-python.c \ - weechat-python.h \ - weechat-python-api.c \ - weechat-python-api.h -python_la_LDFLAGS = -module -python_la_LIBADD = ../lib_weechat_plugins_scripts.la $(PYTHON_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c deleted file mode 100644 index 0dac4b641..000000000 --- a/src/plugins/scripts/python/weechat-python-api.c +++ /dev/null @@ -1,5945 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-python-api.c: python API functions - */ - -#undef _ - -#include <Python.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-python.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *python_function_name = __name; \ - (void) self; \ - if (__init \ - && (!python_current_script || !python_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, \ - python_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, \ - python_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_python_plugin, PYTHON_CURRENT_SCRIPT_NAME, \ - python_function_name, __string) -#define API_RETURN_OK return PyLong_FromLong((long)1); -#define API_RETURN_ERROR return PyLong_FromLong ((long)0); -#define API_RETURN_EMPTY \ - Py_INCREF (Py_None); \ - return Py_None; -#define API_RETURN_STRING(__string) \ - if (__string) \ - return Py_BuildValue ("s", __string); \ - return Py_BuildValue ("s", "") -#define API_RETURN_STRING_FREE(__string) \ - if (__string) \ - { \ - return_value = Py_BuildValue ("s", __string); \ - free (__string); \ - return return_value; \ - } \ - return Py_BuildValue ("s", "") -#define API_RETURN_INT(__int) \ - return PyLong_FromLong((long)__int); -#define API_RETURN_LONG(__long) \ - return PyLong_FromLong(__long); - -#define API_DEF_FUNC(__name) \ - { #__name, &weechat_python_api_##__name, METH_VARARGS, "" } - - -/* - * weechat_python_api_register: startup function for all WeeChat Python scripts - */ - -static PyObject * -weechat_python_api_register (PyObject *self, PyObject *args) -{ - char *name, *author, *version, *license, *shutdown_func, *description; - char *charset; - - API_FUNC(0, "register", API_RETURN_ERROR); - if (python_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, - python_registered_script->name); - API_RETURN_ERROR; - } - python_current_script = NULL; - python_registered_script = NULL; - name = NULL; - author = NULL; - version = NULL; - license = NULL; - description = NULL; - shutdown_func = NULL; - charset = NULL; - if (!PyArg_ParseTuple (args, "sssssss", &name, &author, &version, - &license, &description, &shutdown_func, &charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (script_search (weechat_python_plugin, python_scripts, name)) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, name); - API_RETURN_ERROR; - } - - /* register script */ - python_current_script = script_add (weechat_python_plugin, - &python_scripts, &last_python_script, - (python_current_script_filename) ? - python_current_script_filename : "", - name, author, version, license, - description, shutdown_func, charset); - if (python_current_script) - { - python_registered_script = python_current_script; - if ((weechat_python_plugin->debug >= 2) || !python_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - PYTHON_PLUGIN_NAME, name, version, description); - } - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat_python_api_plugin_get_name: get name of plugin (return "core" for - * WeeChat core) - */ - -static PyObject * -weechat_python_api_plugin_get_name (PyObject *self, PyObject *args) -{ - char *plugin; - const char *result; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - plugin = NULL; - if (!PyArg_ParseTuple (args, "s", &plugin)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_plugin_get_name (API_STR2PTR(plugin)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_charset_set: set script charset - */ - -static PyObject * -weechat_python_api_charset_set (PyObject *self, PyObject *args) -{ - char *charset; - - API_FUNC(1, "charset_set", API_RETURN_ERROR); - charset = NULL; - if (!PyArg_ParseTuple (args, "s", &charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_charset_set (python_current_script, - charset); - - API_RETURN_OK; -} - -/* - * weechat_python_api_iconv_to_internal: convert string to internal WeeChat charset - */ - -static PyObject * -weechat_python_api_iconv_to_internal (PyObject *self, PyObject *args) -{ - char *charset, *string, *result; - PyObject *return_value; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - charset = NULL; - string = NULL; - if (!PyArg_ParseTuple (args, "ss", &charset, &string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_iconv_to_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_iconv_from_internal: convert string from WeeChat internal - * charset to another one - */ - -static PyObject * -weechat_python_api_iconv_from_internal (PyObject *self, PyObject *args) -{ - char *charset, *string, *result; - PyObject *return_value; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - charset = NULL; - string = NULL; - if (!PyArg_ParseTuple (args, "ss", &charset, &string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_iconv_from_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_gettext: get translated string - */ - -static PyObject * -weechat_python_api_gettext (PyObject *self, PyObject *args) -{ - char *string; - const char *result; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - string = NULL; - if (!PyArg_ParseTuple (args, "s", &string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_gettext (string); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_ngettext: get translated string with plural form - */ - -static PyObject * -weechat_python_api_ngettext (PyObject *self, PyObject *args) -{ - char *single, *plural; - const char *result; - int count; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - single = NULL; - plural = NULL; - count = 0; - if (!PyArg_ParseTuple (args, "ssi", &single, &plural, &count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_ngettext (single, plural, count); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other - * "*" are allowed inside mask - */ - -static PyObject * -weechat_python_api_string_match (PyObject *self, PyObject *args) -{ - char *string, *mask; - int case_sensitive, value; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - string = NULL; - mask = NULL; - case_sensitive = 0; - if (!PyArg_ParseTuple (args, "ssi", &string, &mask, &case_sensitive)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_match (string, mask, case_sensitive); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_string_has_highlight: return 1 if string contains a - * highlight (using list of words to - * highlight) - * return 0 if no highlight is found - * in string - */ - -static PyObject * -weechat_python_api_string_has_highlight (PyObject *self, PyObject *args) -{ - char *string, *highlight_words; - int value; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - string = NULL; - highlight_words = NULL; - if (!PyArg_ParseTuple (args, "ss", &string, &highlight_words)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight (string, highlight_words); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_string_has_highlight_regex: return 1 if string contains a - * highlight (using regular - * expression) - * return 0 if no highlight is - * found in string - */ - -static PyObject * -weechat_python_api_string_has_highlight_regex (PyObject *self, PyObject *args) -{ - char *string, *regex; - int value; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - string = NULL; - regex = NULL; - if (!PyArg_ParseTuple (args, "ss", &string, ®ex)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_has_highlight_regex (string, regex); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_string_mask_to_regex: convert a mask (string with only - * "*" as wildcard) to a regex, paying - * attention to special chars in a - * regex - */ - -static PyObject * -weechat_python_api_string_mask_to_regex (PyObject *self, PyObject *args) -{ - char *mask, *result; - PyObject *return_value; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - mask = NULL; - if (!PyArg_ParseTuple (args, "s", &mask)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_mask_to_regex (mask); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_string_remove_color: remove WeeChat color codes from - * string - */ - -static PyObject * -weechat_python_api_string_remove_color (PyObject *self, PyObject *args) -{ - char *string, *replacement, *result; - PyObject *return_value; - - API_FUNC(1, "string_remove_color2", API_RETURN_EMPTY); - string = NULL; - replacement = NULL; - if (!PyArg_ParseTuple (args, "ss", &string, &replacement)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_remove_color (string, replacement); - - API_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; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - string = NULL; - if (!PyArg_ParseTuple (args, "s", &string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_string_is_command_char (string); - - API_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; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - string = NULL; - if (!PyArg_ParseTuple (args, "s", &string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_input_for_buffer (string); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_mkdir_home: create a directory in WeeChat home - */ - -static PyObject * -weechat_python_api_mkdir_home (PyObject *self, PyObject *args) -{ - char *directory; - int mode; - - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - directory = NULL; - mode = 0; - if (!PyArg_ParseTuple (args, "si", &directory, &mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_home (directory, mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_python_api_mkdir: create a directory - */ - -static PyObject * -weechat_python_api_mkdir (PyObject *self, PyObject *args) -{ - char *directory; - int mode; - - API_FUNC(1, "mkdir", API_RETURN_ERROR); - directory = NULL; - mode = 0; - if (!PyArg_ParseTuple (args, "si", &directory, &mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir (directory, mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_python_api_mkdir_parents: create a directory and make parent - * directories as needed - */ - -static PyObject * -weechat_python_api_mkdir_parents (PyObject *self, PyObject *args) -{ - char *directory; - int mode; - - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - directory = NULL; - mode = 0; - if (!PyArg_ParseTuple (args, "si", &directory, &mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (weechat_mkdir_parents (directory, mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_python_api_list_new: create a new list - */ - -static PyObject * -weechat_python_api_list_new (PyObject *self, PyObject *args) -{ - char *result; - PyObject *return_value; - - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_add: add a string to list - */ - -static PyObject * -weechat_python_api_list_add (PyObject *self, PyObject *args) -{ - char *weelist, *data, *where, *user_data, *result; - PyObject *return_value; - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - weelist = NULL; - data = NULL; - where = NULL; - user_data = NULL; - if (!PyArg_ParseTuple (args, "ssss", &weelist, &data, &where, &user_data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(weelist), - data, - where, - API_STR2PTR(user_data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_search: search a string in list - */ - -static PyObject * -weechat_python_api_list_search (PyObject *self, PyObject *args) -{ - char *weelist, *data, *result; - PyObject *return_value; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - weelist = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_search_pos: search position of a string in list - */ - -static PyObject * -weechat_python_api_list_search_pos (PyObject *self, PyObject *args) -{ - char *weelist, *data; - int pos; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - weelist = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - pos = weechat_list_search_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_python_api_list_casesearch: search a string in list (ignore case) - */ - -static PyObject * -weechat_python_api_list_casesearch (PyObject *self, PyObject *args) -{ - char *weelist, *data, *result; - PyObject *return_value; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - weelist = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -static PyObject * -weechat_python_api_list_casesearch_pos (PyObject *self, PyObject *args) -{ - char *weelist, *data; - int pos; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - weelist = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ss", &weelist, &data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - pos = weechat_list_casesearch_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_python_api_list_get: get item by position - */ - -static PyObject * -weechat_python_api_list_get (PyObject *self, PyObject *args) -{ - char *weelist, *result; - int position; - PyObject *return_value; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - weelist = NULL; - position = 0; - if (!PyArg_ParseTuple (args, "si", &weelist, &position)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(weelist), - position)); - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_set: set new value for item - */ - -static PyObject * -weechat_python_api_list_set (PyObject *self, PyObject *args) -{ - char *item, *new_value; - - API_FUNC(1, "list_set", API_RETURN_ERROR); - item = NULL; - new_value = NULL; - if (!PyArg_ParseTuple (args, "ss", &item, &new_value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_set (API_STR2PTR(item), - new_value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_list_next: get next item - */ - -static PyObject * -weechat_python_api_list_next (PyObject *self, PyObject *args) -{ - char *item, *result; - PyObject *return_value; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - item = NULL; - if (!PyArg_ParseTuple (args, "s", &item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(item))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_prev: get previous item - */ - -static PyObject * -weechat_python_api_list_prev (PyObject *self, PyObject *args) -{ - char *item, *result; - PyObject *return_value; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - item = NULL; - if (!PyArg_ParseTuple (args, "s", &item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(item))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_list_string: get string value of item - */ - -static PyObject * -weechat_python_api_list_string (PyObject *self, PyObject *args) -{ - char *item; - const char *result; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - item = NULL; - if (!PyArg_ParseTuple (args, "s", &item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_list_string (API_STR2PTR(item)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_list_size: get number of elements in list - */ - -static PyObject * -weechat_python_api_list_size (PyObject *self, PyObject *args) -{ - char *weelist; - int size; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - weelist = NULL; - if (!PyArg_ParseTuple (args, "s", &weelist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - size = weechat_list_size (API_STR2PTR(weelist)); - - API_RETURN_INT(size); -} - -/* - * weechat_python_api_list_remove: remove item from list - */ - -static PyObject * -weechat_python_api_list_remove (PyObject *self, PyObject *args) -{ - char *weelist, *item; - - API_FUNC(1, "list_remove", API_RETURN_ERROR); - weelist = NULL; - item = NULL; - if (!PyArg_ParseTuple (args, "ss", &weelist, &item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove (API_STR2PTR(weelist), - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_list_remove_all: remove all items from list - */ - -static PyObject * -weechat_python_api_list_remove_all (PyObject *self, PyObject *args) -{ - char *weelist; - - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - weelist = NULL; - if (!PyArg_ParseTuple (args, "s", &weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove_all (API_STR2PTR(weelist)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_list_free: free list - */ - -static PyObject * -weechat_python_api_list_free (PyObject *self, PyObject *args) -{ - char *weelist; - - API_FUNC(1, "list_free", API_RETURN_ERROR); - weelist = NULL; - if (!PyArg_ParseTuple (args, "s", &weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_free (API_STR2PTR(weelist)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_reload_cb: callback for config reload - */ - -int -weechat_python_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat_python_api_config_new: create a new configuration file - */ - -static PyObject * -weechat_python_api_config_new (PyObject *self, PyObject *args) -{ - char *name, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - name = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &name, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new (weechat_python_plugin, - python_current_script, - name, - &weechat_python_api_config_reload_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_read_cb: callback for reading option in section - */ - -int -weechat_python_api_config_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_python_api_config_section_write_cb: callback for writing section - */ - -int -weechat_python_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_python_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_python_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_python_api_config_section_create_option_cb: callback to create an option - */ - -int -weechat_python_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_python_api_config_section_delete_option_cb: callback to delete an option - */ - -int -weechat_python_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat_python_api_config_new_section: create a new section in configuration file - */ - -static PyObject * -weechat_python_api_config_new_section (PyObject *self, PyObject *args) -{ - char *config_file, *name, *function_read, *data_read, *function_write; - char *data_write, *function_write_default, *data_write_default; - char *function_create_option, *data_create_option, *function_delete_option; - char *data_delete_option, *result; - int user_can_add_options, user_can_delete_options; - PyObject *return_value; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - config_file = NULL; - name = NULL; - user_can_add_options = 0; - user_can_delete_options = 0; - function_read = NULL; - data_read = NULL; - function_write = NULL; - data_write = NULL; - function_write_default = NULL; - data_write_default = NULL; - function_create_option = NULL; - data_create_option = NULL; - function_delete_option = NULL; - data_delete_option = NULL; - if (!PyArg_ParseTuple (args, "ssiissssssssss", &config_file, &name, - &user_can_add_options, &user_can_delete_options, - &function_read, &data_read, &function_write, - &data_write, &function_write_default, - &data_write_default, &function_create_option, - &data_create_option, &function_delete_option, - &data_delete_option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new_section (weechat_python_plugin, - python_current_script, - API_STR2PTR(config_file), - name, - user_can_add_options, - user_can_delete_options, - &weechat_python_api_config_read_cb, - function_read, - data_read, - &weechat_python_api_config_section_write_cb, - function_write, - data_write, - &weechat_python_api_config_section_write_default_cb, - function_write_default, - data_write_default, - &weechat_python_api_config_section_create_option_cb, - function_create_option, - data_create_option, - &weechat_python_api_config_section_delete_option_cb, - function_delete_option, - data_delete_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_search_section: search section in configuration file - */ - -static PyObject * -weechat_python_api_config_search_section (PyObject *self, PyObject *args) -{ - char *config_file, *section_name, *result; - PyObject *return_value; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - config_file = NULL; - section_name = NULL; - if (!PyArg_ParseTuple (args, "ss", &config_file, §ion_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(config_file), - section_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_option_check_cb: callback for checking new value - * for option - */ - -int -weechat_python_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_python_api_config_option_change_cb: callback for option changed - */ - -void -weechat_python_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_python_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_python_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_python_api_config_new_option: create a new option in section - */ - -static PyObject * -weechat_python_api_config_new_option (PyObject *self, PyObject *args) -{ - char *config_file, *section, *name, *type, *description, *string_values; - char *default_value, *value, *result; - char *function_check_value, *data_check_value, *function_change; - char *data_change, *function_delete, *data_delete; - int min, max, null_value_allowed; - PyObject *return_value; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - config_file = NULL; - section = NULL; - name = NULL; - type = NULL; - description = NULL; - string_values = NULL; - default_value = NULL; - value = NULL; - function_check_value = NULL; - data_check_value = NULL; - function_change = NULL; - data_change = NULL; - function_delete = NULL; - data_delete = NULL; - if (!PyArg_ParseTuple (args, "ssssssiississssss", &config_file, §ion, &name, - &type, &description, &string_values, &min, &max, - &default_value, &value, &null_value_allowed, - &function_check_value, &data_check_value, - &function_change, &data_change, &function_delete, - &data_delete)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_config_new_option (weechat_python_plugin, - python_current_script, - API_STR2PTR(config_file), - API_STR2PTR(section), - name, - type, - description, - string_values, - min, - max, - default_value, - value, - null_value_allowed, - &weechat_python_api_config_option_check_value_cb, - function_check_value, - data_check_value, - &weechat_python_api_config_option_change_cb, - function_change, - data_change, - &weechat_python_api_config_option_delete_cb, - function_delete, - data_delete)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_search_option: search option in configuration file or section - */ - -static PyObject * -weechat_python_api_config_search_option (PyObject *self, PyObject *args) -{ - char *config_file, *section, *option_name, *result; - PyObject *return_value; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - config_file = NULL; - section = NULL; - option_name = NULL; - if (!PyArg_ParseTuple (args, "sss", &config_file, §ion, &option_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(config_file), - API_STR2PTR(section), - option_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_string_to_boolean: return boolean value of a string - */ - -static PyObject * -weechat_python_api_config_string_to_boolean (PyObject *self, PyObject *args) -{ - char *text; - int value; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - text = NULL; - if (!PyArg_ParseTuple (args, "s", &text)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_string_to_boolean (text); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_option_reset: reset an option with default value - */ - -static PyObject * -weechat_python_api_config_option_reset (PyObject *self, PyObject *args) -{ - char *option; - int run_callback, rc; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - option = NULL; - run_callback = 0; - if (!PyArg_ParseTuple (args, "si", &option, &run_callback)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = weechat_config_option_reset (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_option_set: set new value for option - */ - -static PyObject * -weechat_python_api_config_option_set (PyObject *self, PyObject *args) -{ - char *option, *new_value; - int run_callback, rc; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - option = NULL; - new_value = NULL; - run_callback = 0; - if (!PyArg_ParseTuple (args, "ssi", &option, &new_value, &run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = weechat_config_option_set (API_STR2PTR(option), - new_value, - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_option_set_null: set null (undefined) value for - * option - */ - -static PyObject * -weechat_python_api_config_option_set_null (PyObject *self, PyObject *args) -{ - char *option; - int run_callback, rc; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - option = NULL; - run_callback = 0; - if (!PyArg_ParseTuple (args, "si", &option, &run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = weechat_config_option_set_null (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_option_unset: unset an option - */ - -static PyObject * -weechat_python_api_config_option_unset (PyObject *self, PyObject *args) -{ - char *option; - int rc; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - rc = weechat_config_option_unset (API_STR2PTR(option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_option_rename: rename an option - */ - -static PyObject * -weechat_python_api_config_option_rename (PyObject *self, PyObject *args) -{ - char *option, *new_name; - - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - option = NULL; - new_name = NULL; - if (!PyArg_ParseTuple (args, "ss", &option, &new_name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_option_rename (API_STR2PTR(option), - new_name); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_option_is_null: return 1 if value of option is null - */ - -static PyObject * -weechat_python_api_config_option_is_null (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_is_null (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_option_default_is_null: return 1 if default value - * of option is null - */ - -static PyObject * -weechat_python_api_config_option_default_is_null (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - value = weechat_config_option_default_is_null (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_boolean: return boolean value of option - */ - -static PyObject * -weechat_python_api_config_boolean (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_boolean_default: return default boolean value of option - */ - -static PyObject * -weechat_python_api_config_boolean_default (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_boolean_default (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_integer: return integer value of option - */ - -static PyObject * -weechat_python_api_config_integer (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_integer_default: return default integer value of option - */ - -static PyObject * -weechat_python_api_config_integer_default (PyObject *self, PyObject *args) -{ - char *option; - int value; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_config_integer_default (API_STR2PTR(option)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_config_string: return string value of option - */ - -static PyObject * -weechat_python_api_config_string (PyObject *self, PyObject *args) -{ - char *option; - const char *result; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_config_string_default: return default string value of option - */ - -static PyObject * -weechat_python_api_config_string_default (PyObject *self, PyObject *args) -{ - char *option; - const char *result; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string_default (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_config_color: return color value of option - */ - -static PyObject * -weechat_python_api_config_color (PyObject *self, PyObject *args) -{ - char *option; - const char *result; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_config_color_default: return default color value of option - */ - -static PyObject * -weechat_python_api_config_color_default (PyObject *self, PyObject *args) -{ - char *option; - const char *result; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color_default (API_STR2PTR(option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_config_write_option: write an option in configuration file - */ - -static PyObject * -weechat_python_api_config_write_option (PyObject *self, PyObject *args) -{ - char *config_file, *option; - - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - config_file = NULL; - option = NULL; - if (!PyArg_ParseTuple (args, "ss", &config_file, &option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_write_option (API_STR2PTR(config_file), - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_write_line: write a line in configuration file - */ - -static PyObject * -weechat_python_api_config_write_line (PyObject *self, PyObject *args) -{ - char *config_file, *option_name, *value; - - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - config_file = NULL; - option_name = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "sss", &config_file, &option_name, &value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_config_write_line (API_STR2PTR(config_file), - option_name, - "%s", - value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_write: write configuration file - */ - -static PyObject * -weechat_python_api_config_write (PyObject *self, PyObject *args) -{ - char *config_file; - int rc; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - config_file = NULL; - if (!PyArg_ParseTuple (args, "s", &config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_write (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_read: read configuration file - */ - -static PyObject * -weechat_python_api_config_read (PyObject *self, PyObject *args) -{ - char *config_file; - int rc; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - config_file = NULL; - if (!PyArg_ParseTuple (args, "s", &config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_read (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_reload: reload configuration file - */ - -static PyObject * -weechat_python_api_config_reload (PyObject *self, PyObject *args) -{ - char *config_file; - int rc; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - config_file = NULL; - if (!PyArg_ParseTuple (args, "s", &config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_reload (API_STR2PTR(config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_option_free: free an option in configuration file - */ - -static PyObject * -weechat_python_api_config_option_free (PyObject *self, PyObject *args) -{ - char *option; - - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_option_free (weechat_python_plugin, - python_current_script, - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_section_free_options: free all options of a section - * in configuration file - */ - -static PyObject * -weechat_python_api_config_section_free_options (PyObject *self, PyObject *args) -{ - char *section; - - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - section = NULL; - if (!PyArg_ParseTuple (args, "s", §ion)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free_options (weechat_python_plugin, - python_current_script, - API_STR2PTR(section)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_section_free: free section in configuration file - */ - -static PyObject * -weechat_python_api_config_section_free (PyObject *self, PyObject *args) -{ - char *section; - - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - section = NULL; - if (!PyArg_ParseTuple (args, "s", §ion)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free (weechat_python_plugin, - python_current_script, - API_STR2PTR(section)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_free: free configuration file - */ - -static PyObject * -weechat_python_api_config_free (PyObject *self, PyObject *args) -{ - char *config_file; - - API_FUNC(1, "config_free", API_RETURN_ERROR); - config_file = NULL; - if (!PyArg_ParseTuple (args, "s", &config_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_free (weechat_python_plugin, - python_current_script, - API_STR2PTR(config_file)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_get: get config option - */ - -static PyObject * -weechat_python_api_config_get (PyObject *self, PyObject *args) -{ - char *option, *result; - PyObject *return_value; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_get (option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_config_get_plugin: get value of a plugin option - */ - -static PyObject * -weechat_python_api_config_get_plugin (PyObject *self, PyObject *args) -{ - char *option; - const char *result; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_api_config_get_plugin (weechat_python_plugin, - python_current_script, - option); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_config_is_set_plugin: check if a plugin option is set - */ - -static PyObject * -weechat_python_api_config_is_set_plugin (PyObject *self, PyObject *args) -{ - char *option; - int rc; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = script_api_config_is_set_plugin (weechat_python_plugin, - python_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_set_plugin: set value of a plugin option - */ - -static PyObject * -weechat_python_api_config_set_plugin (PyObject *self, PyObject *args) -{ - char *option, *value; - int rc; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - option = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "ss", &option, &value)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - rc = script_api_config_set_plugin (weechat_python_plugin, - python_current_script, - option, - value); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_config_set_desc_plugin: set description of a plugin option - */ - -static PyObject * -weechat_python_api_config_set_desc_plugin (PyObject *self, PyObject *args) -{ - char *option, *description; - - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - option = NULL; - description = NULL; - if (!PyArg_ParseTuple (args, "ss", &option, &description)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_set_desc_plugin (weechat_python_plugin, - python_current_script, - option, - description); - - API_RETURN_OK; -} - -/* - * weechat_python_api_config_unset_plugin: unset plugin option - */ - -static PyObject * -weechat_python_api_config_unset_plugin (PyObject *self, PyObject *args) -{ - char *option; - int rc; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - option = NULL; - if (!PyArg_ParseTuple (args, "s", &option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - rc = script_api_config_unset_plugin (weechat_python_plugin, - python_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_key_bind: bind key(s) - */ - -static PyObject * -weechat_python_api_key_bind (PyObject *self, PyObject *args) -{ - char *context; - struct t_hashtable *hashtable; - PyObject *dict; - int num_keys; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - context = NULL; - if (!PyArg_ParseTuple (args, "sO", &context, &dict)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hashtable = weechat_python_dict_to_hashtable (dict, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (context, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_python_api_key_unbind: unbind key(s) - */ - -static PyObject * -weechat_python_api_key_unbind (PyObject *self, PyObject *args) -{ - char *context, *key; - int num_keys; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - context = NULL; - key = NULL; - if (!PyArg_ParseTuple (args, "ss", &context, &key)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - num_keys = weechat_key_unbind (context, key); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_python_api_prefix: get a prefix, used for display - */ - -static PyObject * -weechat_python_api_prefix (PyObject *self, PyObject *args) -{ - char *prefix; - const char *result; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - prefix = NULL; - if (!PyArg_ParseTuple (args, "s", &prefix)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_prefix (prefix); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_color: get a color code, used for display - */ - -static PyObject * -weechat_python_api_color (PyObject *self, PyObject *args) -{ - char *color; - const char *result; - - API_FUNC(0, "color", API_RETURN_EMPTY); - color = NULL; - if (!PyArg_ParseTuple (args, "s", &color)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_color (color); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_prnt: print message in a buffer - */ - -static PyObject * -weechat_python_api_prnt (PyObject *self, PyObject *args) -{ - char *buffer, *message; - - API_FUNC(0, "prnt", API_RETURN_ERROR); - buffer = NULL; - message = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer), - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_python_api_prnt_date_tags: print message in a buffer with optional - * date and tags - */ - -static PyObject * -weechat_python_api_prnt_date_tags (PyObject *self, PyObject *args) -{ - char *buffer, *tags, *message; - int date; - - API_FUNC(1, "prnt_date_tags", API_RETURN_ERROR); - buffer = NULL; - date = 0; - tags = NULL; - message = NULL; - if (!PyArg_ParseTuple (args, "siss", &buffer, &date, &tags, &message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf_date_tags (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer), - date, - tags, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_python_api_prnt_y: print message in a buffer with free content - */ - -static PyObject * -weechat_python_api_prnt_y (PyObject *self, PyObject *args) -{ - char *buffer, *message; - int y; - - API_FUNC(1, "prnt_y", API_RETURN_ERROR); - buffer = NULL; - y = 0; - message = NULL; - if (!PyArg_ParseTuple (args, "sis", &buffer, &y, &message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_printf_y (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer), - y, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_python_api_log_print: print message in WeeChat log file - */ - -static PyObject * -weechat_python_api_log_print (PyObject *self, PyObject *args) -{ - char *message; - - API_FUNC(1, "log_print", API_RETURN_ERROR); - message = NULL; - if (!PyArg_ParseTuple (args, "s", &message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_log_printf (weechat_python_plugin, - python_current_script, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_python_api_hook_command_cb: callback for command hooked - */ - -int -weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_command: hook a command - */ - -static PyObject * -weechat_python_api_hook_command (PyObject *self, PyObject *args) -{ - char *command, *description, *arguments, *args_description, *completion; - char *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - command = NULL; - description = NULL; - arguments = NULL; - args_description = NULL; - completion = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sssssss", &command, &description, &arguments, - &args_description, &completion, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_command (weechat_python_plugin, - python_current_script, - command, - description, - arguments, - args_description, - completion, - &weechat_python_api_hook_command_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_python_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_command_run: hook a command_run - */ - -static PyObject * -weechat_python_api_hook_command_run (PyObject *self, PyObject *args) -{ - char *command, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - command = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &command, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_command_run (weechat_python_plugin, - python_current_script, - command, - &weechat_python_api_hook_command_run_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_python_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_timer: hook a timer - */ - -static PyObject * -weechat_python_api_hook_timer (PyObject *self, PyObject *args) -{ - int interval, align_second, max_calls; - char *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - interval = 10; - align_second = 0; - max_calls = 0; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "iiiss", &interval, &align_second, &max_calls, - &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_timer (weechat_python_plugin, - python_current_script, - interval, - align_second, - max_calls, - &weechat_python_api_hook_timer_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_python_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_fd: hook a fd - */ - -static PyObject * -weechat_python_api_hook_fd (PyObject *self, PyObject *args) -{ - int fd, read, write, exception; - char *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - fd = 0; - read = 0; - write = 0; - exception = 0; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "iiiiss", &fd, &read, &write, &exception, - &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_fd (weechat_python_plugin, - python_current_script, - fd, - read, - write, - exception, - &weechat_python_api_hook_fd_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_process_cb: callback for process hooked - */ - -int -weechat_python_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = PyLong_FromLong((long)return_code); - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssOss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - { - Py_XDECREF((PyObject *)func_argv[2]); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_process: hook a process - */ - -static PyObject * -weechat_python_api_hook_process (PyObject *self, PyObject *args) -{ - char *command, *function, *data, *result; - int timeout; - PyObject *return_value; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - command = NULL; - timeout = 0; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "siss", &command, &timeout, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_process (weechat_python_plugin, - python_current_script, - command, - timeout, - &weechat_python_api_hook_process_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_process_hashtable: hook a process with options in - * a hashtable - */ - -static PyObject * -weechat_python_api_hook_process_hashtable (PyObject *self, PyObject *args) -{ - char *command, *function, *data, *result; - int timeout; - struct t_hashtable *options; - PyObject *dict, *return_value; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - command = NULL; - options = NULL; - timeout = 0; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sOiss", &command, &dict, &timeout, &function, - &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - options = weechat_python_dict_to_hashtable (dict, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_python_plugin, - python_current_script, - command, - options, - timeout, - &weechat_python_api_hook_process_cb, - function, - data)); - - if (options) - weechat_hashtable_free (options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_python_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_connect: hook a connection - */ - -static PyObject * -weechat_python_api_hook_connect (PyObject *self, PyObject *args) -{ - char *proxy, *address, *local_hostname, *function, *data, *result; - int port, sock, ipv6; - PyObject *return_value; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - proxy = NULL; - address = NULL; - port = 0; - sock = 0; - ipv6 = 0; - local_hostname = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssiiisss", &proxy, &address, &port, &sock, - &ipv6, &local_hostname, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_connect (weechat_python_plugin, - python_current_script, - proxy, - address, - port, - sock, - ipv6, - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - local_hostname, - &weechat_python_api_hook_connect_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_print_cb: callback for print hooked - */ - -int -weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_print: hook a print - */ - -static PyObject * -weechat_python_api_hook_print (PyObject *self, PyObject *args) -{ - char *buffer, *tags, *message, *function, *data, *result; - int strip_colors; - PyObject *return_value; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - buffer = NULL; - tags = NULL; - message = NULL; - strip_colors = 0; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sssiss", &buffer, &tags, &message, - &strip_colors, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_print (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer), - tags, - message, - strip_colors, - &weechat_python_api_hook_print_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_python_api_hook_signal_cb (void *data, const char *signal, const char *type_data, - void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_signal: hook a signal - */ - -static PyObject * -weechat_python_api_hook_signal (PyObject *self, PyObject *args) -{ - char *signal, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - signal = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &signal, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_signal (weechat_python_plugin, - python_current_script, - signal, - &weechat_python_api_hook_signal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_signal_send: send a signal - */ - -static PyObject * -weechat_python_api_hook_signal_send (PyObject *self, PyObject *args) -{ - char *signal, *type_data, *signal_data, *error; - int number; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - signal = NULL; - type_data = NULL; - signal_data = NULL; - if (!PyArg_ParseTuple (args, "sss", &signal, &type_data, &signal_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - weechat_hook_signal_send (signal, type_data, signal_data); - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - error = NULL; - number = (int)strtol (signal_data, &error, 10); - if (error && !error[0]) - { - weechat_hook_signal_send (signal, type_data, &number); - } - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - weechat_hook_signal_send (signal, type_data, - API_STR2PTR(signal_data)); - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_python_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_python_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = weechat_python_hashtable_to_dict (hashtable); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssO", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - { - Py_XDECREF((PyObject *)func_argv[2]); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_hsignal: hook a hsignal - */ - -static PyObject * -weechat_python_api_hook_hsignal (PyObject *self, PyObject *args) -{ - char *signal, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - signal = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &signal, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_hsignal (weechat_python_plugin, - python_current_script, - signal, - &weechat_python_api_hook_hsignal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_hsignal_send: send a hsignal - */ - -static PyObject * -weechat_python_api_hook_hsignal_send (PyObject *self, PyObject *args) -{ - char *signal; - struct t_hashtable *hashtable; - PyObject *dict; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - signal = NULL; - if (!PyArg_ParseTuple (args, "sO", &signal, &dict)) - API_WRONG_ARGS(API_RETURN_ERROR); - - hashtable = weechat_python_dict_to_hashtable (dict, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (signal, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_OK; -} - -/* - * weechat_python_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_python_api_hook_config_cb (void *data, const char *option, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_config: hook a config option - */ - -static PyObject * -weechat_python_api_hook_config (PyObject *self, PyObject *args) -{ - char *option, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - option = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &option, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_config (weechat_python_plugin, - python_current_script, - option, - &weechat_python_api_hook_config_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_python_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_hook_completion: hook a completion - */ - -static PyObject * -weechat_python_api_hook_completion (PyObject *self, PyObject *args) -{ - char *completion, *description, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - completion = NULL; - description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function, - &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_completion (weechat_python_plugin, - python_current_script, - completion, - description, - &weechat_python_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_completion_list_add: add a word to list for a completion - */ - -static PyObject * -weechat_python_api_hook_completion_list_add (PyObject *self, PyObject *args) -{ - char *completion, *word, *where; - int nick_completion; - - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - completion = NULL; - word = NULL; - nick_completion = 0; - where = NULL; - if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion, - &where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - -/* - * weechat_python_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_python_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat_python_api_hook_modifier: hook a modifier - */ - -static PyObject * -weechat_python_api_hook_modifier (PyObject *self, PyObject *args) -{ - char *modifier, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - modifier = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &modifier, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_modifier (weechat_python_plugin, - python_current_script, - modifier, - &weechat_python_api_hook_modifier_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_modifier_exec: execute a modifier hook - */ - -static PyObject * -weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args) -{ - char *modifier, *modifier_data, *string, *result; - PyObject *return_value; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - modifier = NULL; - modifier_data = NULL; - string = NULL; - if (!PyArg_ParseTuple (args, "sss", &modifier, &modifier_data, &string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_modifier_exec (modifier, modifier_data, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_python_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat_python_api_hook_info: hook an info - */ - -static PyObject * -weechat_python_api_hook_info (PyObject *self, PyObject *args) -{ - char *info_name, *description, *args_description, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - info_name = NULL; - description = NULL; - args_description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sssss", &info_name, &description, - &args_description, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_info (weechat_python_plugin, - python_current_script, - info_name, - description, - args_description, - &weechat_python_api_hook_info_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_python_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - struct t_hashtable *ret_hashtable; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = weechat_python_hashtable_to_dict (hashtable); - - ret_hashtable = weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssO", func_argv); - - if (func_argv[2]) - { - Py_XDECREF((PyObject *)func_argv[2]); - } - - return ret_hashtable; - } - - return NULL; -} - -/* - * weechat_python_api_hook_info_hashtable: hook an info_hashtable - */ - -static PyObject * -weechat_python_api_hook_info_hashtable (PyObject *self, PyObject *args) -{ - char *info_name, *description, *args_description, *output_description; - char *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - info_name = NULL; - description = NULL; - args_description = NULL; - output_description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssssss", &info_name, &description, - &args_description, &output_description, - &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_python_plugin, - python_current_script, - info_name, - description, - args_description, - output_description, - &weechat_python_api_hook_info_hashtable_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_python_api_hook_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat_python_api_hook_infolist: hook an infolist - */ - -static PyObject * -weechat_python_api_hook_infolist (PyObject *self, PyObject *args) -{ - char *infolist_name, *description, *pointer_description, *args_description; - char *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - infolist_name = NULL; - description = NULL; - pointer_description = NULL; - args_description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssssss", &infolist_name, &description, - &pointer_description, &args_description, &function, - &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_infolist (weechat_python_plugin, - python_current_script, - infolist_name, - description, - pointer_description, - args_description, - &weechat_python_api_hook_infolist_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_python_api_hook_focus_cb (void *data, - struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - struct t_hashtable *ret_hashtable; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = weechat_python_hashtable_to_dict (info); - - ret_hashtable = weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sO", func_argv); - if (func_argv[1]) - { - Py_XDECREF((PyObject *)func_argv[1]); - } - - return ret_hashtable; - } - - return NULL; -} - -/* - * weechat_python_api_hook_focus: hook a focus - */ - -static PyObject * -weechat_python_api_hook_focus (PyObject *self, PyObject *args) -{ - char *area, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - area = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &area, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_focus (weechat_python_plugin, - python_current_script, - area, - &weechat_python_api_hook_focus_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_unhook: unhook something - */ - -static PyObject * -weechat_python_api_unhook (PyObject *self, PyObject *args) -{ - char *hook; - - API_FUNC(1, "unhook", API_RETURN_ERROR); - hook = NULL; - if (!PyArg_ParseTuple (args, "s", &hook)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_unhook (weechat_python_plugin, - python_current_script, - API_STR2PTR(hook)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_unhook_all: unhook all for script - */ - -static PyObject * -weechat_python_api_unhook_all (PyObject *self, PyObject *args) -{ - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_python_plugin, python_current_script); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_python_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_buffer_close_cb: callback for buffer closed - */ - -int -weechat_python_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_buffer_new: create a new buffer - */ - -static PyObject * -weechat_python_api_buffer_new (PyObject *self, PyObject *args) -{ - char *name, *function_input, *data_input, *function_close, *data_close; - char *result; - PyObject *return_value; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - name = NULL; - function_input = NULL; - data_input = NULL; - function_close = NULL; - data_close = NULL; - if (!PyArg_ParseTuple (args, "sssss", &name, &function_input, &data_input, - &function_close, &data_close)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_buffer_new (weechat_python_plugin, - python_current_script, - name, - &weechat_python_api_buffer_input_data_cb, - function_input, - data_input, - &weechat_python_api_buffer_close_cb, - function_close, - data_close)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_buffer_search: search a buffer - */ - -static PyObject * -weechat_python_api_buffer_search (PyObject *self, PyObject *args) -{ - char *plugin, *name; - char *result; - PyObject *return_value; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - plugin = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "ss", &plugin, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search (plugin, name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_buffer_search_main: search main buffer (WeeChat core buffer) - */ - -static PyObject * -weechat_python_api_buffer_search_main (PyObject *self, PyObject *args) -{ - char *result; - PyObject *return_value; - - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_current_buffer: get current buffer - */ - -static PyObject * -weechat_python_api_current_buffer (PyObject *self, PyObject *args) -{ - char *result; - PyObject *return_value; - - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_buffer_clear: clear a buffer - */ - -static PyObject * -weechat_python_api_buffer_clear (PyObject *self, PyObject *args) -{ - char *buffer; - - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - buffer = NULL; - if (!PyArg_ParseTuple (args, "s", &buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_clear (API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_close: close a buffer - */ - -static PyObject * -weechat_python_api_buffer_close (PyObject *self, PyObject *args) -{ - char *buffer; - - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - buffer = NULL; - if (!PyArg_ParseTuple (args, "s", &buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_buffer_close (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_merge: merge a buffer to another buffer - */ - -static PyObject * -weechat_python_api_buffer_merge (PyObject *self, PyObject *args) -{ - char *buffer, *target_buffer; - - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - buffer = NULL; - target_buffer = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &target_buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_merge (API_STR2PTR(buffer), - API_STR2PTR(target_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_unmerge: unmerge a buffer from group of merged - * buffers - */ - -static PyObject * -weechat_python_api_buffer_unmerge (PyObject *self, PyObject *args) -{ - char *buffer; - int number; - - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - buffer = NULL; - number = 0; - if (!PyArg_ParseTuple (args, "si", &buffer, &number)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_unmerge (API_STR2PTR(buffer), number); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_get_integer: get a buffer property as integer - */ - -static PyObject * -weechat_python_api_buffer_get_integer (PyObject *self, PyObject *args) -{ - char *buffer, *property; - int value; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - buffer = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_buffer_get_integer (API_STR2PTR(buffer), property); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_buffer_get_string: get a buffer property as string - */ - -static PyObject * -weechat_python_api_buffer_get_string (PyObject *self, PyObject *args) -{ - char *buffer, *property; - const char *result; - - API_FUNC(1, "buffer_get_string", API_RETURN_ERROR); - buffer = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_buffer_get_string (API_STR2PTR(buffer), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_buffer_get_pointer: get a buffer property as pointer - */ - -static PyObject * -weechat_python_api_buffer_get_pointer (PyObject *self, PyObject *args) -{ - char *buffer, *property, *result; - PyObject *return_value; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - buffer = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(buffer), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_buffer_set: set a buffer property - */ - -static PyObject * -weechat_python_api_buffer_set (PyObject *self, PyObject *args) -{ - char *buffer, *property, *value; - - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - buffer = NULL; - property = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &property, &value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_set (API_STR2PTR(buffer), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_buffer_string_replace_local_var: replace local variables ($var) in a string, - * using value of local variables - */ - -static PyObject * -weechat_python_api_buffer_string_replace_local_var (PyObject *self, PyObject *args) -{ - char *buffer, *string, *result; - PyObject *return_value; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - buffer = NULL; - string = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &string)) - API_WRONG_ARGS(API_RETURN_ERROR); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(buffer), string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_buffer_match_list: return 1 if buffer matches list of - * buffers - */ - -static PyObject * -weechat_python_api_buffer_match_list (PyObject *self, PyObject *args) -{ - char *buffer, *string; - int value; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - buffer = NULL; - string = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_buffer_match_list (API_STR2PTR(buffer), string); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_current_window: get current window - */ - -static PyObject * -weechat_python_api_current_window (PyObject *self, PyObject *args) -{ - char *result; - PyObject *return_value; - - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_window_search_with_buffer: search a window with buffer - * pointer - */ - -static PyObject * -weechat_python_api_window_search_with_buffer (PyObject *self, PyObject *args) -{ - char *buffer, *result; - PyObject *return_value; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - buffer = NULL; - if (!PyArg_ParseTuple (args, "s", &buffer)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(buffer))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_window_get_integer get a window property as integer - */ - -static PyObject * -weechat_python_api_window_get_integer (PyObject *self, PyObject *args) -{ - char *window, *property; - int value; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - window = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &window, &property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_window_get_integer (API_STR2PTR(window), property); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_window_get_string: get a window property as string - */ - -static PyObject * -weechat_python_api_window_get_string (PyObject *self, PyObject *args) -{ - char *window, *property; - const char *result; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - window = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &window, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_window_get_string (API_STR2PTR(window), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_window_get_pointer: get a window property as pointer - */ - -static PyObject * -weechat_python_api_window_get_pointer (PyObject *self, PyObject *args) -{ - char *window, *property, *result; - PyObject *return_value; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - window = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &window, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(window), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_window_set_title: set window title - */ - -static PyObject * -weechat_python_api_window_set_title (PyObject *self, PyObject *args) -{ - char *title; - - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - title = NULL; - if (!PyArg_ParseTuple (args, "s", &title)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_window_set_title (title); - - API_RETURN_OK; -} - -/* - * weechat_python_api_nicklist_add_group: add a group in nicklist - */ - -static PyObject * -weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args) -{ - char *buffer, *parent_group, *name, *color, *result; - int visible; - PyObject *return_value; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - buffer = NULL; - parent_group = NULL; - name = NULL; - color = NULL; - visible = 0; - if (!PyArg_ParseTuple (args, "ssssi", &buffer, &parent_group, &name, - &color, &visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(buffer), - API_STR2PTR(parent_group), - name, - color, - visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_search_group: search a group in nicklist - */ - -static PyObject * -weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args) -{ - char *buffer, *from_group, *name, *result; - PyObject *return_value; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - buffer = NULL; - from_group = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_add_nick: add a nick in nicklist - */ - -static PyObject * -weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args) -{ - char *buffer, *group, *name, *color, *prefix, *prefix_color, *result; - int visible; - PyObject *return_value; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - buffer = NULL; - group = NULL; - name = NULL; - color = NULL; - prefix = NULL; - prefix_color = NULL; - visible = 0; - if (!PyArg_ParseTuple (args, "ssssssi", &buffer, &group, &name, &color, - &prefix, &prefix_color, &visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(buffer), - API_STR2PTR(group), - name, - color, - prefix, - prefix_color, - visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_search_nick: search a nick in nicklist - */ - -static PyObject * -weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args) -{ - char *buffer, *from_group, *name, *result; - PyObject *return_value; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - buffer = NULL; - from_group = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &from_group, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_remove_group: remove a group from nicklist - */ - -static PyObject * -weechat_python_api_nicklist_remove_group (PyObject *self, PyObject *args) -{ - char *buffer, *group; - - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - buffer = NULL; - group = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &group)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_group (API_STR2PTR(buffer), - API_STR2PTR(group)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_nicklist_remove_nick: remove a nick from nicklist - */ - -static PyObject * -weechat_python_api_nicklist_remove_nick (PyObject *self, PyObject *args) -{ - char *buffer, *nick; - - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - buffer = NULL; - nick = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &nick)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_nick (API_STR2PTR(buffer), - API_STR2PTR(nick)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_nicklist_remove_all: remove all groups/nicks from nicklist - */ - -static PyObject * -weechat_python_api_nicklist_remove_all (PyObject *self, PyObject *args) -{ - char *buffer; - - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - buffer = NULL; - if (!PyArg_ParseTuple (args, "s", &buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_all (API_STR2PTR(buffer)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_nicklist_group_get_integer get a group property as integer - */ - -static PyObject * -weechat_python_api_nicklist_group_get_integer (PyObject *self, PyObject *args) -{ - char *buffer, *group, *property; - int value; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - buffer = NULL; - group = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &group, &property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_nicklist_group_get_integer (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_nicklist_group_get_string: get a group property as string - */ - -static PyObject * -weechat_python_api_nicklist_group_get_string (PyObject *self, PyObject *args) -{ - char *buffer, *group, *property; - const char *result; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_ERROR); - buffer = NULL; - group = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &group, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_nicklist_group_get_string (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_nicklist_group_get_pointer: get a group property as pointer - */ - -static PyObject * -weechat_python_api_nicklist_group_get_pointer (PyObject *self, PyObject *args) -{ - char *buffer, *group, *property, *result; - PyObject *return_value; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - buffer = NULL; - group = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &group, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(group), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_group_set: set a group property - */ - -static PyObject * -weechat_python_api_nicklist_group_set (PyObject *self, PyObject *args) -{ - char *buffer, *group, *property, *value; - - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - buffer = NULL; - group = NULL; - property = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "ssss", &buffer, &group, &property, &value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_group_set (API_STR2PTR(buffer), - API_STR2PTR(group), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_nicklist_nick_get_integer get a nick property as integer - */ - -static PyObject * -weechat_python_api_nicklist_nick_get_integer (PyObject *self, PyObject *args) -{ - char *buffer, *nick, *property; - int value; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - buffer = NULL; - nick = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &nick, &property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_nicklist_nick_get_integer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_nicklist_nick_get_string: get a nick property as string - */ - -static PyObject * -weechat_python_api_nicklist_nick_get_string (PyObject *self, PyObject *args) -{ - char *buffer, *nick, *property; - const char *result; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_ERROR); - buffer = NULL; - nick = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &nick, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_nicklist_nick_get_pointer: get a nick property as pointer - */ - -static PyObject * -weechat_python_api_nicklist_nick_get_pointer (PyObject *self, PyObject *args) -{ - char *buffer, *nick, *property, *result; - PyObject *return_value; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - buffer = NULL; - nick = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "sss", &buffer, &nick, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_nicklist_nick_set: set a nick property - */ - -static PyObject * -weechat_python_api_nicklist_nick_set (PyObject *self, PyObject *args) -{ - char *buffer, *nick, *property, *value; - - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - buffer = NULL; - nick = NULL; - property = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "ssss", &buffer, &nick, &property, &value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_nick_set (API_STR2PTR(buffer), - API_STR2PTR(nick), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_bar_item_search: search a bar item - */ - -static PyObject * -weechat_python_api_bar_item_search (PyObject *self, PyObject *args) -{ - char *name, *result; - PyObject *return_value; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - name = NULL; - if (!PyArg_ParseTuple (args, "s", &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_item_search (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_python_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat_python_api_bar_item_new: add a new bar item - */ - -static PyObject * -weechat_python_api_bar_item_new (PyObject *self, PyObject *args) -{ - char *name, *function, *data, *result; - PyObject *return_value; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - name = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &name, &function, &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_bar_item_new (weechat_python_plugin, - python_current_script, - name, - &weechat_python_api_bar_item_build_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_bar_item_update: update a bar item on screen - */ - -static PyObject * -weechat_python_api_bar_item_update (PyObject *self, PyObject *args) -{ - char *name; - - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - name = NULL; - if (!PyArg_ParseTuple (args, "s", &name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_item_update (name); - - API_RETURN_OK; -} - -/* - * weechat_python_api_bar_item_remove: remove a bar item - */ - -static PyObject * -weechat_python_api_bar_item_remove (PyObject *self, PyObject *args) -{ - char *item; - - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - item = NULL; - if (!PyArg_ParseTuple (args, "s", &item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_bar_item_remove (weechat_python_plugin, - python_current_script, - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_bar_search: search a bar - */ - -static PyObject * -weechat_python_api_bar_search (PyObject *self, PyObject *args) -{ - char *name, *result; - PyObject *return_value; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - name = NULL; - if (!PyArg_ParseTuple (args, "s", &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_search (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_bar_new: add a new bar - */ - -static PyObject * -weechat_python_api_bar_new (PyObject *self, PyObject *args) -{ - char *name, *hidden, *priority, *type, *conditions, *position; - char *filling_top_bottom, *filling_left_right, *size, *size_max; - char *color_fg, *color_delim, *color_bg, *separator, *items, *result; - PyObject *return_value; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - name = NULL; - hidden = NULL; - priority = NULL; - type = NULL; - conditions = NULL; - position = NULL; - filling_top_bottom = NULL; - filling_left_right = NULL; - size = NULL; - size_max = NULL; - color_fg = NULL; - color_delim = NULL; - color_bg = NULL; - separator = NULL; - items = NULL; - if (!PyArg_ParseTuple (args, "sssssssssssssss", &name, &hidden, &priority, - &type, &conditions, &position, &filling_top_bottom, - &filling_left_right, &size, &size_max, &color_fg, - &color_delim, &color_bg, &separator, &items)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_new (name, - hidden, - priority, - type, - conditions, - position, - filling_top_bottom, - filling_left_right, - size, - size_max, - color_fg, - color_delim, - color_bg, - separator, - items)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_bar_set: set a bar property - */ - -static PyObject * -weechat_python_api_bar_set (PyObject *self, PyObject *args) -{ - char *bar, *property, *value; - - API_FUNC(1, "bar_set", API_RETURN_ERROR); - bar = NULL; - property = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "sss", &bar, &property, &value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_set (API_STR2PTR(bar), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_python_api_bar_update: update a bar on screen - */ - -static PyObject * -weechat_python_api_bar_update (PyObject *self, PyObject *args) -{ - char *name; - - API_FUNC(1, "bar_item", API_RETURN_ERROR); - name = NULL; - if (!PyArg_ParseTuple (args, "s", &name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_update (name); - - API_RETURN_OK; -} - -/* - * weechat_python_api_bar_remove: remove a bar - */ - -static PyObject * -weechat_python_api_bar_remove (PyObject *self, PyObject *args) -{ - char *bar; - - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - bar = NULL; - if (!PyArg_ParseTuple (args, "s", &bar)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_remove (API_STR2PTR(bar)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_command: send command to server - */ - -static PyObject * -weechat_python_api_command (PyObject *self, PyObject *args) -{ - char *buffer, *command; - - API_FUNC(1, "command", API_RETURN_ERROR); - buffer = NULL; - command = NULL; - if (!PyArg_ParseTuple (args, "ss", &buffer, &command)) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_command (weechat_python_plugin, - python_current_script, - API_STR2PTR(buffer), - command); - - API_RETURN_OK; -} - -/* - * weechat_python_api_info_get: get info (as string) - */ - -static PyObject * -weechat_python_api_info_get (PyObject *self, PyObject *args) -{ - char *info_name, *arguments; - const char *result; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - info_name = NULL; - arguments = NULL; - if (!PyArg_ParseTuple (args, "ss", &info_name, &arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_info_get (info_name, arguments); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_info_get_hashtable: get info (as hashtable) - */ - -static PyObject * -weechat_python_api_info_get_hashtable (PyObject *self, PyObject *args) -{ - char *info_name; - struct t_hashtable *hashtable, *result_hashtable; - PyObject *dict, *result_dict; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - info_name = NULL; - if (!PyArg_ParseTuple (args, "sO", &info_name, &dict)) - API_WRONG_ARGS(API_RETURN_EMPTY); - hashtable = weechat_python_dict_to_hashtable (dict, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (info_name, hashtable); - result_dict = weechat_python_hashtable_to_dict (result_hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - return result_dict; -} - -/* - * weechat_python_api_infolist_new: create new infolist - */ - -static PyObject * -weechat_python_api_infolist_new (PyObject *self, PyObject *args) -{ - char *result; - PyObject *return_value; - - /* make C compiler happy */ - (void) args; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_new_item: create new item in infolist - */ - -static PyObject * -weechat_python_api_infolist_new_item (PyObject *self, PyObject *args) -{ - char *infolist, *result; - PyObject *return_value; - - API_FUNC(1, "infolist_new_item", API_RETURN_EMPTY); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(infolist))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_new_var_integer: create new integer variable in - * infolist - */ - -static PyObject * -weechat_python_api_infolist_new_var_integer (PyObject *self, PyObject *args) -{ - char *infolist, *name, *result; - int value; - PyObject *return_value; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_EMPTY); - infolist = NULL; - name = NULL; - value = 0; - if (!PyArg_ParseTuple (args, "ssi", &infolist, &name, &value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_new_var_string: create new string variable in - * infolist - */ - -static PyObject * -weechat_python_api_infolist_new_var_string (PyObject *self, PyObject *args) -{ - char *infolist, *name, *value, *result; - PyObject *return_value; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_EMPTY); - infolist = NULL; - name = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "sss", &infolist, &name, &value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_new_var_pointer: create new pointer variable in - * infolist - */ - -static PyObject * -weechat_python_api_infolist_new_var_pointer (PyObject *self, PyObject *args) -{ - char *infolist, *name, *value, *result; - PyObject *return_value; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_EMPTY); - infolist = NULL; - name = NULL; - value = NULL; - if (!PyArg_ParseTuple (args, "sss", &infolist, &name, &value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(infolist), - name, - API_STR2PTR(value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_new_var_time: create new time variable in - * infolist - */ - -static PyObject * -weechat_python_api_infolist_new_var_time (PyObject *self, PyObject *args) -{ - char *infolist, *name, *result; - int value; - PyObject *return_value; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_EMPTY); - infolist = NULL; - name = NULL; - value = 0; - if (!PyArg_ParseTuple (args, "ssi", &infolist, &name, &value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(infolist), - name, - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_get: get list with infos - */ - -static PyObject * -weechat_python_api_infolist_get (PyObject *self, PyObject *args) -{ - char *name, *pointer, *arguments, *result; - PyObject *return_value; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - name = NULL; - pointer = NULL; - arguments = NULL; - if (!PyArg_ParseTuple (args, "sss", &name, &pointer, &arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_get (name, - API_STR2PTR(pointer), - arguments)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_next: move item pointer to next item in infolist - */ - -static PyObject * -weechat_python_api_infolist_next (PyObject *self, PyObject *args) -{ - char *infolist; - int value; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_next (API_STR2PTR(infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_infolist_prev: move item pointer to previous item in infolist - */ - -static PyObject * -weechat_python_api_infolist_prev (PyObject *self, PyObject *args) -{ - char *infolist; - int value; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_prev (API_STR2PTR(infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_infolist_reset_item_cursor: reset pointer to current item - * in infolist - */ - -static PyObject * -weechat_python_api_infolist_reset_item_cursor (PyObject *self, PyObject *args) -{ - char *infolist; - - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_reset_item_cursor (API_STR2PTR(infolist)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_infolist_fields: get list of fields for current item of infolist - */ - -static PyObject * -weechat_python_api_infolist_fields (PyObject *self, PyObject *args) -{ - char *infolist; - const char *result; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_fields (API_STR2PTR(infolist)); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_infolist_integer: get integer value of a variable in infolist - */ - -static PyObject * -weechat_python_api_infolist_integer (PyObject *self, PyObject *args) -{ - char *infolist, *variable; - int value; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - infolist = NULL; - variable = NULL; - if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_infolist_integer (API_STR2PTR(infolist), - variable); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_infolist_string: get string value of a variable in infolist - */ - -static PyObject * -weechat_python_api_infolist_string (PyObject *self, PyObject *args) -{ - char *infolist, *variable; - const char *result; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - infolist = NULL; - variable = NULL; - if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_string (API_STR2PTR(infolist), - variable); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_infolist_pointer: get pointer value of a variable in infolist - */ - -static PyObject * -weechat_python_api_infolist_pointer (PyObject *self, PyObject *args) -{ - char *infolist, *variable, *result; - PyObject *return_value; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - infolist = NULL; - variable = NULL; - if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(infolist), - variable)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_time: get time value of a variable in infolist - */ - -static PyObject * -weechat_python_api_infolist_time (PyObject *self, PyObject *args) -{ - char *infolist, *variable, timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - PyObject *return_value; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - infolist = NULL; - variable = NULL; - if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(infolist), - variable); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_infolist_free: free infolist - */ - -static PyObject * -weechat_python_api_infolist_free (PyObject *self, PyObject *args) -{ - char *infolist; - - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - infolist = NULL; - if (!PyArg_ParseTuple (args, "s", &infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_free (API_STR2PTR(infolist)); - - API_RETURN_OK; -} - -/* - * weechat_python_api_hdata_get: get hdata - */ - -static PyObject * -weechat_python_api_hdata_get (PyObject *self, PyObject *args) -{ - char *name, *result; - PyObject *return_value; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - name = NULL; - if (!PyArg_ParseTuple (args, "s", &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_get (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hdata_get_var_offset: get offset of variable in hdata - */ - -static PyObject * -weechat_python_api_hdata_get_var_offset (PyObject *self, PyObject *args) -{ - char *hdata, *name; - int value; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - hdata = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_get_var_offset (API_STR2PTR(hdata), name); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_hdata_get_var_type_string: get type of variable as string - * in hdata - */ - -static PyObject * -weechat_python_api_hdata_get_var_type_string (PyObject *self, PyObject *args) -{ - char *hdata, *name; - const char *result; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - hdata = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_hdata_get_var_array_size: get array size for variable in - * hdata - */ - -static PyObject * -weechat_python_api_hdata_get_var_array_size (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - value = weechat_hdata_get_var_array_size (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_hdata_get_var_array_size_string: get array size for variable - * in hdata (as string) - */ - -static PyObject * -weechat_python_api_hdata_get_var_array_size_string (PyObject *self, - PyObject *args) -{ - char *hdata, *pointer, *name; - const char *result; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_hdata_get_var_hdata: get hdata for variable in hdata - */ - -static PyObject * -weechat_python_api_hdata_get_var_hdata (PyObject *self, PyObject *args) -{ - char *hdata, *name; - const char *result; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - hdata = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_hdata_get_list: get list pointer in hdata - */ - -static PyObject * -weechat_python_api_hdata_get_list (PyObject *self, PyObject *args) -{ - char *hdata, *name, *result; - PyObject *return_value; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - hdata = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(hdata), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hdata_check_pointer: check pointer with hdata/list - */ - -static PyObject * -weechat_python_api_hdata_check_pointer (PyObject *self, PyObject *args) -{ - char *hdata, *list, *pointer; - int value; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - hdata = NULL; - list = NULL; - pointer = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &list, &pointer)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_check_pointer (API_STR2PTR(hdata), - API_STR2PTR(list), - API_STR2PTR(pointer)); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_hdata_move: move pointer to another element in list - */ - -static PyObject * -weechat_python_api_hdata_move (PyObject *self, PyObject *args) -{ - char *result, *hdata, *pointer; - int count; - PyObject *return_value; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - count = 0; - if (!PyArg_ParseTuple (args, "ssi", &hdata, &pointer, &count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_move (API_STR2PTR(hdata), - API_STR2PTR(pointer), - count)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hdata_char: get char value of a variable in structure - * using hdata - */ - -static PyObject * -weechat_python_api_hdata_char (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = (int)weechat_hdata_char (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_hdata_integer: get integer value of a variable in - * structure using hdata - */ - -static PyObject * -weechat_python_api_hdata_integer (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - int value; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - value = weechat_hdata_integer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(value); -} - -/* - * weechat_python_api_hdata_long: get long value of a variable in structure - * using hdata - */ - -static PyObject * -weechat_python_api_hdata_long (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - long value; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - value = weechat_hdata_long (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_LONG(value); -} - -/* - * weechat_python_api_hdata_string: get string value of a variable in structure - * using hdata - */ - -static PyObject * -weechat_python_api_hdata_string (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - const char *result; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_hdata_pointer: get pointer value of a variable in - * structure using hdata - */ - -static PyObject * -weechat_python_api_hdata_pointer (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name, *result; - PyObject *return_value; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hdata_time: get time value of a variable in structure - * using hdata - */ - -static PyObject * -weechat_python_api_hdata_time (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name, timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - PyObject *return_value; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_hdata_hashtable: get hashtable value of a variable in - * structure using hdata - */ - -static PyObject * -weechat_python_api_hdata_hashtable (PyObject *self, PyObject *args) -{ - char *hdata, *pointer, *name; - PyObject *result_dict; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - hdata = NULL; - pointer = NULL; - name = NULL; - if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result_dict = weechat_python_hashtable_to_dict ( - weechat_hdata_hashtable (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - return result_dict; -} - -/* - * weechat_python_api_hdata_get_string: get hdata property as string - */ - -static PyObject * -weechat_python_api_hdata_get_string (PyObject *self, PyObject *args) -{ - char *hdata, *property; - const char *result; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - hdata = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &hdata, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hdata_get_string (API_STR2PTR(hdata), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_python_api_upgrade_new: create an upgrade file - */ - -static PyObject * -weechat_python_api_upgrade_new (PyObject *self, PyObject *args) -{ - char *filename, *result; - int write; - PyObject *return_value; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - filename = NULL; - write = 0; - if (!PyArg_ParseTuple (args, "si", &filename, &write)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_upgrade_new (filename, write)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_python_api_upgrade_write_object: write object in upgrade file - */ - -static PyObject * -weechat_python_api_upgrade_write_object (PyObject *self, PyObject *args) -{ - char *upgrade_file, *infolist; - int object_id, rc; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - upgrade_file = NULL; - object_id = 0; - infolist = NULL; - if (!PyArg_ParseTuple (args, "sis", &upgrade_file, &object_id, &infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file), - object_id, - API_STR2PTR(infolist)); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_upgrade_read_cb: callback for reading object in upgrade file - */ - -int -weechat_python_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_python_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_python_api_upgrade_read: read upgrade file - */ - -static PyObject * -weechat_python_api_upgrade_read (PyObject *self, PyObject *args) -{ - char *upgrade_file, *function, *data; - int rc; - - API_FUNC(1, "upgrade_read", API_RETURN_INT(0)); - upgrade_file = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "sss", &upgrade_file, &function, &data)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - rc = script_api_upgrade_read (weechat_python_plugin, - python_current_script, - API_STR2PTR(upgrade_file), - &weechat_python_api_upgrade_read_cb, - function, - data); - - API_RETURN_INT(rc); -} - -/* - * weechat_python_api_upgrade_close: close upgrade file - */ - -static PyObject * -weechat_python_api_upgrade_close (PyObject *self, PyObject *args) -{ - char *upgrade_file; - - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - upgrade_file = NULL; - if (!PyArg_ParseTuple (args, "s", &upgrade_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_upgrade_close (API_STR2PTR(upgrade_file)); - - API_RETURN_OK; -} - -/* - * Python subroutines - */ - -PyMethodDef weechat_python_funcs[] = -{ - API_DEF_FUNC(register), - API_DEF_FUNC(plugin_get_name), - API_DEF_FUNC(charset_set), - API_DEF_FUNC(iconv_to_internal), - API_DEF_FUNC(iconv_from_internal), - API_DEF_FUNC(gettext), - API_DEF_FUNC(ngettext), - API_DEF_FUNC(string_match), - API_DEF_FUNC(string_has_highlight), - API_DEF_FUNC(string_has_highlight_regex), - API_DEF_FUNC(string_mask_to_regex), - API_DEF_FUNC(string_remove_color), - API_DEF_FUNC(string_is_command_char), - API_DEF_FUNC(string_input_for_buffer), - API_DEF_FUNC(mkdir_home), - API_DEF_FUNC(mkdir), - API_DEF_FUNC(mkdir_parents), - API_DEF_FUNC(list_new), - API_DEF_FUNC(list_add), - API_DEF_FUNC(list_search), - API_DEF_FUNC(list_search_pos), - API_DEF_FUNC(list_casesearch), - API_DEF_FUNC(list_casesearch_pos), - API_DEF_FUNC(list_get), - API_DEF_FUNC(list_set), - API_DEF_FUNC(list_next), - API_DEF_FUNC(list_prev), - API_DEF_FUNC(list_string), - API_DEF_FUNC(list_size), - API_DEF_FUNC(list_remove), - API_DEF_FUNC(list_remove_all), - API_DEF_FUNC(list_free), - API_DEF_FUNC(config_new), - API_DEF_FUNC(config_new_section), - API_DEF_FUNC(config_search_section), - API_DEF_FUNC(config_new_option), - API_DEF_FUNC(config_search_option), - API_DEF_FUNC(config_string_to_boolean), - API_DEF_FUNC(config_option_reset), - API_DEF_FUNC(config_option_set), - API_DEF_FUNC(config_option_set_null), - API_DEF_FUNC(config_option_unset), - API_DEF_FUNC(config_option_rename), - API_DEF_FUNC(config_option_is_null), - API_DEF_FUNC(config_option_default_is_null), - API_DEF_FUNC(config_boolean), - API_DEF_FUNC(config_boolean_default), - API_DEF_FUNC(config_integer), - API_DEF_FUNC(config_integer_default), - API_DEF_FUNC(config_string), - API_DEF_FUNC(config_string_default), - API_DEF_FUNC(config_color), - API_DEF_FUNC(config_color_default), - API_DEF_FUNC(config_write_option), - API_DEF_FUNC(config_write_line), - API_DEF_FUNC(config_write), - API_DEF_FUNC(config_read), - API_DEF_FUNC(config_reload), - API_DEF_FUNC(config_option_free), - API_DEF_FUNC(config_section_free_options), - API_DEF_FUNC(config_section_free), - API_DEF_FUNC(config_free), - API_DEF_FUNC(config_get), - API_DEF_FUNC(config_get_plugin), - API_DEF_FUNC(config_is_set_plugin), - API_DEF_FUNC(config_set_plugin), - API_DEF_FUNC(config_set_desc_plugin), - API_DEF_FUNC(config_unset_plugin), - API_DEF_FUNC(key_bind), - API_DEF_FUNC(key_unbind), - API_DEF_FUNC(prefix), - API_DEF_FUNC(color), - API_DEF_FUNC(prnt), - API_DEF_FUNC(prnt_date_tags), - API_DEF_FUNC(prnt_y), - API_DEF_FUNC(log_print), - API_DEF_FUNC(hook_command), - API_DEF_FUNC(hook_command_run), - API_DEF_FUNC(hook_timer), - API_DEF_FUNC(hook_fd), - API_DEF_FUNC(hook_process), - API_DEF_FUNC(hook_process_hashtable), - API_DEF_FUNC(hook_connect), - API_DEF_FUNC(hook_print), - API_DEF_FUNC(hook_signal), - API_DEF_FUNC(hook_signal_send), - API_DEF_FUNC(hook_hsignal), - API_DEF_FUNC(hook_hsignal_send), - API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_list_add), - API_DEF_FUNC(hook_modifier), - API_DEF_FUNC(hook_modifier_exec), - API_DEF_FUNC(hook_info), - API_DEF_FUNC(hook_info_hashtable), - API_DEF_FUNC(hook_infolist), - API_DEF_FUNC(hook_focus), - API_DEF_FUNC(unhook), - API_DEF_FUNC(unhook_all), - API_DEF_FUNC(buffer_new), - API_DEF_FUNC(buffer_search), - API_DEF_FUNC(buffer_search_main), - API_DEF_FUNC(current_buffer), - API_DEF_FUNC(buffer_clear), - API_DEF_FUNC(buffer_close), - API_DEF_FUNC(buffer_merge), - API_DEF_FUNC(buffer_unmerge), - API_DEF_FUNC(buffer_get_integer), - API_DEF_FUNC(buffer_get_string), - API_DEF_FUNC(buffer_get_pointer), - API_DEF_FUNC(buffer_set), - API_DEF_FUNC(buffer_string_replace_local_var), - API_DEF_FUNC(buffer_match_list), - API_DEF_FUNC(current_window), - API_DEF_FUNC(window_search_with_buffer), - API_DEF_FUNC(window_get_integer), - API_DEF_FUNC(window_get_string), - API_DEF_FUNC(window_get_pointer), - API_DEF_FUNC(window_set_title), - API_DEF_FUNC(nicklist_add_group), - API_DEF_FUNC(nicklist_search_group), - API_DEF_FUNC(nicklist_add_nick), - API_DEF_FUNC(nicklist_search_nick), - API_DEF_FUNC(nicklist_remove_group), - API_DEF_FUNC(nicklist_remove_nick), - API_DEF_FUNC(nicklist_remove_all), - API_DEF_FUNC(nicklist_group_get_integer), - API_DEF_FUNC(nicklist_group_get_string), - API_DEF_FUNC(nicklist_group_get_pointer), - API_DEF_FUNC(nicklist_group_set), - API_DEF_FUNC(nicklist_nick_get_integer), - API_DEF_FUNC(nicklist_nick_get_string), - API_DEF_FUNC(nicklist_nick_get_pointer), - API_DEF_FUNC(nicklist_nick_set), - API_DEF_FUNC(bar_item_search), - API_DEF_FUNC(bar_item_new), - API_DEF_FUNC(bar_item_update), - API_DEF_FUNC(bar_item_remove), - API_DEF_FUNC(bar_search), - API_DEF_FUNC(bar_new), - API_DEF_FUNC(bar_set), - API_DEF_FUNC(bar_update), - API_DEF_FUNC(bar_remove), - API_DEF_FUNC(command), - API_DEF_FUNC(info_get), - API_DEF_FUNC(info_get_hashtable), - API_DEF_FUNC(infolist_new), - API_DEF_FUNC(infolist_new_item), - API_DEF_FUNC(infolist_new_var_integer), - API_DEF_FUNC(infolist_new_var_string), - API_DEF_FUNC(infolist_new_var_pointer), - API_DEF_FUNC(infolist_new_var_time), - API_DEF_FUNC(infolist_get), - API_DEF_FUNC(infolist_next), - API_DEF_FUNC(infolist_prev), - API_DEF_FUNC(infolist_reset_item_cursor), - API_DEF_FUNC(infolist_fields), - API_DEF_FUNC(infolist_integer), - API_DEF_FUNC(infolist_string), - API_DEF_FUNC(infolist_pointer), - API_DEF_FUNC(infolist_time), - API_DEF_FUNC(infolist_free), - API_DEF_FUNC(hdata_get), - API_DEF_FUNC(hdata_get_var_offset), - API_DEF_FUNC(hdata_get_var_type_string), - API_DEF_FUNC(hdata_get_var_array_size), - API_DEF_FUNC(hdata_get_var_array_size_string), - API_DEF_FUNC(hdata_get_var_hdata), - API_DEF_FUNC(hdata_get_list), - API_DEF_FUNC(hdata_check_pointer), - API_DEF_FUNC(hdata_move), - API_DEF_FUNC(hdata_char), - API_DEF_FUNC(hdata_integer), - API_DEF_FUNC(hdata_long), - API_DEF_FUNC(hdata_string), - API_DEF_FUNC(hdata_pointer), - API_DEF_FUNC(hdata_time), - API_DEF_FUNC(hdata_hashtable), - API_DEF_FUNC(hdata_get_string), - API_DEF_FUNC(upgrade_new), - API_DEF_FUNC(upgrade_write_object), - API_DEF_FUNC(upgrade_read), - API_DEF_FUNC(upgrade_close), - { NULL, NULL, 0, NULL } -}; diff --git a/src/plugins/scripts/python/weechat-python-api.h b/src/plugins/scripts/python/weechat-python-api.h deleted file mode 100644 index 4c12f2916..000000000 --- a/src/plugins/scripts/python/weechat-python-api.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_PYTHON_API_H -#define __WEECHAT_PYTHON_API_H 1 - -extern PyMethodDef weechat_python_funcs[]; - -extern int weechat_python_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_python_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); - -#endif /* __WEECHAT_PYTHON_API_H */ diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c deleted file mode 100644 index 993a089b5..000000000 --- a/src/plugins/scripts/python/weechat-python.c +++ /dev/null @@ -1,1259 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-python.c: python plugin for WeeChat - */ - -#undef _ - -#include <Python.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-python.h" -#include "weechat-python-api.h" - - -WEECHAT_PLUGIN_NAME(PYTHON_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of python scripts")); -WEECHAT_PLUGIN_AUTHOR("Sebastien Helleu <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_python_plugin = NULL; - -int python_quiet; -struct t_plugin_script *python_scripts = NULL; -struct t_plugin_script *last_python_script = NULL; -struct t_plugin_script *python_current_script = NULL; -struct t_plugin_script *python_registered_script = NULL; -const char *python_current_script_filename = NULL; -PyThreadState *python_mainThreadState = NULL; -char *python2_bin = NULL; - -/* outputs subroutines */ -static PyObject *weechat_python_output (PyObject *self, PyObject *args); -static PyMethodDef weechat_python_output_funcs[] = { - { "write", weechat_python_output, METH_VARARGS, "" }, - { NULL, NULL, 0, NULL } -}; - -#if PY_MAJOR_VERSION >= 3 -/* module definition for python >= 3.x */ -static struct PyModuleDef moduleDef = { - PyModuleDef_HEAD_INIT, - "weechat", - NULL, - -1, - weechat_python_funcs, - NULL, - NULL, - NULL, - NULL -}; -static struct PyModuleDef moduleDefOutputs = { - PyModuleDef_HEAD_INIT, - "weechatOutputs", - NULL, - -1, - weechat_python_output_funcs, - NULL, - NULL, - NULL, - NULL -}; -#endif - -/* - * string used to execute action "install": - * when signal "python_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *python_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "python_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *python_action_remove_list = NULL; - -char python_buffer_output[128]; - - -/* - * weechat_python_set_python2_bin: set path to python 2.x interpreter - */ - -void -weechat_python_set_python2_bin () -{ - const char *dir_separator; - char *path, **paths, bin[4096]; - char *versions[] = { "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2", NULL }; - int num_paths, i, j, rc; - struct stat stat_buf; - - python2_bin = NULL; - - dir_separator = weechat_info_get ("dir_separator", ""); - path = getenv ("PATH"); - - if (dir_separator && path) - { - paths = weechat_string_split (path, ":", 0, 0, &num_paths); - if (paths) - { - for (i = 0; i < num_paths; i++) - { - for (j = 0; versions[j]; j++) - { - snprintf (bin, sizeof (bin), "%s%s%s%s", - paths[i], dir_separator, "python", - versions[j]); - rc = stat (bin, &stat_buf); - if ((rc == 0) && (S_ISREG(stat_buf.st_mode))) - { - python2_bin = strdup (bin); - break; - } - } - if (python2_bin) - break; - } - weechat_string_free_split (paths); - } - } - - if (!python2_bin) - python2_bin = strdup ("python"); -} - -/* - * weechat_python_unicode_to_string: convert a python unicode to a C UTF-8 - * string - * Note: result has to be freed after use - */ - -char * -weechat_python_unicode_to_string (PyObject *obj) -{ - PyObject *utf8string; - char *str; - - str = NULL; - - utf8string = PyUnicode_AsUTF8String (obj); - if (utf8string) - { - if (PyBytes_AsString (utf8string)) - str = strdup (PyBytes_AsString (utf8string)); - Py_XDECREF(utf8string); - } - - return str; -} - -/* - * weechat_python_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_python_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - PyObject *dict, *dict_key, *dict_value; - - /* make C compiler happy */ - (void) hashtable; - - dict = (PyObject *)data; - - dict_key = Py_BuildValue ("s", key); - dict_value = Py_BuildValue ("s", value); - - PyDict_SetItem (dict, dict_key, dict_value); - - Py_DECREF (dict_key); - Py_DECREF (dict_value); -} - -/* - * weechat_python_hashtable_to_dict: get python dictionary with a WeeChat - * hashtable - */ - -PyObject * -weechat_python_hashtable_to_dict (struct t_hashtable *hashtable) -{ - PyObject *dict; - - dict = PyDict_New (); - if (!dict) - { - Py_INCREF(Py_None); - return Py_None; - } - - weechat_hashtable_map_string (hashtable, - &weechat_python_hashtable_map_cb, - dict); - - return dict; -} - -/* - * weechat_python_dict_to_hashtable: get WeeChat hashtable with python - * dictionary - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after - * use with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_python_dict_to_hashtable (PyObject *dict, int hashtable_size) -{ - struct t_hashtable *hashtable; - PyObject *key, *value; - Py_ssize_t pos; - char *str_key, *str_value; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - pos = 0; - while (PyDict_Next (dict, &pos, &key, &value)) - { - str_key = NULL; - str_value = NULL; - if (PyBytes_Check (key)) - { - if (PyBytes_AsString (key)) - str_key = strdup (PyBytes_AsString (key)); - } - else - str_key = weechat_python_unicode_to_string (key); - if (PyBytes_Check (value)) - { - if (PyBytes_AsString (value)) - str_value = strdup (PyBytes_AsString (value)); - } - else - str_value = weechat_python_unicode_to_string (value); - - if (str_key) - weechat_hashtable_set (hashtable, str_key, str_value); - - if (str_key) - free (str_key); - if (str_value) - free (str_value); - } - - return hashtable; -} - -/* - * weechat_python_exec: execute a python function - */ - -void * -weechat_python_exec (struct t_plugin_script *script, - int ret_type, const char *function, - char *format, void **argv) -{ - struct t_plugin_script *old_python_current_script; - PyThreadState *old_interpreter; - PyObject *evMain, *evDict, *evFunc, *rc; - void *argv2[16], *ret_value; - int i, argc, *ret_int; - - /* PyEval_AcquireLock (); */ - - old_python_current_script = python_current_script; - old_interpreter = NULL; - if (script->interpreter) - { - old_interpreter = PyThreadState_Swap (NULL); - PyThreadState_Swap (script->interpreter); - } - - evMain = PyImport_AddModule ((char *) "__main__"); - evDict = PyModule_GetDict (evMain); - evFunc = PyDict_GetItemString (evDict, function); - - if ( !(evFunc && PyCallable_Check (evFunc)) ) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to run function \"%s\""), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, function); - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - if (old_interpreter) - PyThreadState_Swap (old_interpreter); - return NULL; - } - - python_current_script = script; - - if (argv && argv[0]) - { - argc = strlen (format); - for (i = 0; i < 16; i++) - { - argv2[i] = (i < argc) ? argv[i] : NULL; - } - rc = PyObject_CallFunction (evFunc, format, - argv2[0], argv2[1], - argv2[2], argv2[3], - argv2[4], argv2[5], - argv2[6], argv2[7], - argv2[8], argv2[9], - argv2[10], argv2[11], - argv2[12], argv2[13], - argv2[14], argv2[15]); - } - else - { - rc = PyObject_CallFunction (evFunc, NULL); - } - - ret_value = NULL; - - /* - * ugly hack : rc = NULL while 'return weechat.WEECHAT_RC_OK .... - * because of '#define WEECHAT_RC_OK 0' - */ - if (rc == NULL) - rc = PyLong_FromLong ((long)0); - - if (PyErr_Occurred()) - { - PyErr_Print (); - Py_XDECREF(rc); - } - else if ((ret_type == WEECHAT_SCRIPT_EXEC_STRING) && (PyUnicode_Check (rc))) - { - ret_value = weechat_python_unicode_to_string (rc); - Py_XDECREF(rc); - } - else if ((ret_type == WEECHAT_SCRIPT_EXEC_STRING) && (PyBytes_Check (rc))) - { - if (PyBytes_AsString (rc)) - ret_value = strdup (PyBytes_AsString (rc)); - else - ret_value = NULL; - Py_XDECREF(rc); - } - else if ((ret_type == WEECHAT_SCRIPT_EXEC_INT) && (PyLong_Check (rc))) - { - ret_int = malloc (sizeof (*ret_int)); - if (ret_int) - *ret_int = (int) PyLong_AsLong(rc); - ret_value = ret_int; - Py_XDECREF(rc); - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_value = weechat_python_dict_to_hashtable (rc, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - Py_XDECREF(rc); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" must return " - "a valid value"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, function); - } - - if (!ret_value) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: error in function \"%s\""), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, function); - } - - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - - python_current_script = old_python_current_script; - - if (old_interpreter) - PyThreadState_Swap (old_interpreter); - - return ret_value; -} - -/* - * weechat_python_output: redirection for stdout and stderr - */ - -static PyObject * -weechat_python_output (PyObject *self, PyObject *args) -{ - char *msg, *m, *p; - - /* make C compiler happy */ - (void) self; - - msg = NULL; - - if (!PyArg_ParseTuple (args, "s", &msg)) - { - if (strlen(python_buffer_output) > 0) - { - weechat_printf (NULL, - weechat_gettext ("%s: stdout/stderr: %s%s"), - PYTHON_PLUGIN_NAME, python_buffer_output, ""); - python_buffer_output[0] = '\0'; - } - } - else - { - m = msg; - while ((p = strchr (m, '\n')) != NULL) - { - *p = '\0'; - if (strlen (m) + strlen (python_buffer_output) > 0) - { - weechat_printf (NULL, - weechat_gettext ("%s: stdout/stderr: %s%s"), - PYTHON_PLUGIN_NAME, python_buffer_output, m); - } - *p = '\n'; - python_buffer_output[0] = '\0'; - m = ++p; - } - - if (strlen(m) + strlen(python_buffer_output) > sizeof(python_buffer_output)) - { - weechat_printf (NULL, - weechat_gettext ("%s: stdout/stderr: %s%s"), - PYTHON_PLUGIN_NAME, python_buffer_output, m); - python_buffer_output[0] = '\0'; - } - else - strcat (python_buffer_output, m); - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* - * weechat_python_init_module_weechat: initialize the "weechat" module - */ - -#if PY_MAJOR_VERSION >= 3 -static PyObject *weechat_python_init_module_weechat () -#else -void weechat_python_init_module_weechat () -#endif -{ - PyObject *weechat_module, *weechat_dict; - -#if PY_MAJOR_VERSION >= 3 - /* python >= 3.x */ - weechat_module = PyModule_Create (&moduleDef); -#else - /* python <= 2.x */ - weechat_module = Py_InitModule ("weechat", weechat_python_funcs); -#endif - - if (!weechat_module) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to initialize WeeChat " - "module"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); -#if PY_MAJOR_VERSION >= 3 - return NULL; -#else - return; -#endif - } - - /* define some constants */ - weechat_dict = PyModule_GetDict(weechat_module); - PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK", PyLong_FromLong((long) WEECHAT_RC_OK)); - PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_EAT", PyLong_FromLong((long) WEECHAT_RC_OK_EAT)); - PyDict_SetItemString(weechat_dict, "WEECHAT_RC_ERROR", PyLong_FromLong((long) WEECHAT_RC_ERROR)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_READ_OK", PyLong_FromLong((long) WEECHAT_CONFIG_READ_OK)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_READ_MEMORY_ERROR", PyLong_FromLong((long) WEECHAT_CONFIG_READ_MEMORY_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_READ_FILE_NOT_FOUND", PyLong_FromLong((long) WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_WRITE_OK", PyLong_FromLong((long) WEECHAT_CONFIG_WRITE_OK)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_WRITE_ERROR", PyLong_FromLong((long) WEECHAT_CONFIG_WRITE_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_WRITE_MEMORY_ERROR", PyLong_FromLong((long) WEECHAT_CONFIG_WRITE_MEMORY_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_SET_OK_CHANGED)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_SET_ERROR", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_SET_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_UNSET_OK_RESET)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)); - PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_OPTION_UNSET_ERROR", PyLong_FromLong((long) WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_SORT", PyUnicode_FromString(WEECHAT_LIST_POS_SORT)); - PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_BEGINNING", PyUnicode_FromString(WEECHAT_LIST_POS_BEGINNING)); - PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_END", PyUnicode_FromString(WEECHAT_LIST_POS_END)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_LOW", PyUnicode_FromString(WEECHAT_HOTLIST_LOW)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_MESSAGE", PyUnicode_FromString(WEECHAT_HOTLIST_MESSAGE)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_PRIVATE", PyUnicode_FromString(WEECHAT_HOTLIST_PRIVATE)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOTLIST_HIGHLIGHT", PyUnicode_FromString(WEECHAT_HOTLIST_HIGHLIGHT)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_PROCESS_RUNNING", PyLong_FromLong((long) WEECHAT_HOOK_PROCESS_RUNNING)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_PROCESS_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_PROCESS_ERROR)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_OK", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_OK)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_PROXY_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_PROXY_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_MEMORY_ERROR", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_MEMORY_ERROR)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_CONNECT_TIMEOUT", PyLong_FromLong((long) WEECHAT_HOOK_CONNECT_TIMEOUT)); - - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_STRING", PyUnicode_FromString(WEECHAT_HOOK_SIGNAL_STRING)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_INT", PyUnicode_FromString(WEECHAT_HOOK_SIGNAL_INT)); - PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_POINTER", PyUnicode_FromString(WEECHAT_HOOK_SIGNAL_POINTER)); - -#if PY_MAJOR_VERSION >= 3 - return weechat_module; -#endif -} - -/* - * weechat_python_load: load a Python script - */ - -int -weechat_python_load (const char *filename) -{ - char *argv[] = { "__weechat_plugin__" , NULL }; -#if PY_MAJOR_VERSION >= 3 - wchar_t *wargv[] = { NULL, NULL }; -#endif - FILE *fp; - PyThreadState *python_current_interpreter; - PyObject *weechat_outputs, *python_path, *path; - const char *weechat_home; - char *str_home; - int len; - - if ((fp = fopen (filename, "r")) == NULL) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not found"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, filename); - return 0; - } - - if ((weechat_python_plugin->debug >= 2) || !python_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - PYTHON_PLUGIN_NAME, filename); - } - - python_current_script = NULL; - python_registered_script = NULL; - - /* PyEval_AcquireLock (); */ - python_current_interpreter = Py_NewInterpreter (); -#if PY_MAJOR_VERSION >= 3 - /* python >= 3.x */ - len = strlen (argv[0]); - wargv[0] = malloc ((len + 1) * sizeof (wargv[0][0])); - if (wargv[0]) - { - if (mbstowcs (wargv[0], argv[0], len) == (size_t)(-1)) - { - free (wargv[0]); - wargv[0] = NULL; - } - PySys_SetArgv(1, wargv); - if (wargv[0]) - free (wargv[0]); - } -#else - /* python <= 2.x */ - PySys_SetArgv(1, argv); -#endif - - if (!python_current_interpreter) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to create new " - "sub-interpreter"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - fclose (fp); - /* PyEval_ReleaseLock (); */ - return 0; - } - - PyThreadState_Swap (python_current_interpreter); - - /* adding $weechat_dir/python in $PYTHONPATH */ - python_path = PySys_GetObject ("path"); - weechat_home = weechat_info_get ("weechat_dir", ""); - if (weechat_home) - { - len = strlen (weechat_home) + 1 + strlen (PYTHON_PLUGIN_NAME) + 1; - str_home = malloc (len); - if (str_home) - { - snprintf (str_home, len, "%s/python", weechat_home); - path = PyBytes_FromString (str_home); - if (path != NULL) - { - PyList_Insert (python_path, 0, path); - Py_DECREF (path); - } - free (str_home); - } - } - -#if PY_MAJOR_VERSION >= 3 - /* python 3.x (or newer) */ - weechat_outputs = PyModule_Create (&moduleDefOutputs); -#else - /* python 2.x */ - weechat_outputs = Py_InitModule("weechatOutputs", - weechat_python_output_funcs); -#endif - - if (!weechat_outputs) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to redirect stdout and " - "stderr"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - } - else - { - if (PySys_SetObject("stdout", weechat_outputs) == -1) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to redirect stdout"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - } - if (PySys_SetObject("stderr", weechat_outputs) == -1) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to redirect stderr"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - } - } - - python_current_script_filename = filename; - - if (PyRun_SimpleFile (fp, filename) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to parse file \"%s\""), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, filename); - fclose (fp); - - if (PyErr_Occurred ()) - PyErr_Print (); - - /* if script was registered, remove it from list */ - if (python_current_script != NULL) - { - script_remove (weechat_python_plugin, - &python_scripts, &last_python_script, - python_current_script); - } - - Py_EndInterpreter (python_current_interpreter); - /* PyEval_ReleaseLock (); */ - - return 0; - } - - if (PyErr_Occurred ()) - PyErr_Print (); - - fclose (fp); - - if (!python_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, filename); - - if (PyErr_Occurred ()) - PyErr_Print (); - Py_EndInterpreter (python_current_interpreter); - /* PyEval_ReleaseLock (); */ - - return 0; - } - python_current_script = python_registered_script; - - python_current_script->interpreter = (PyThreadState *) python_current_interpreter; - /* PyEval_ReleaseThread (python_current_script->interpreter); */ - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_python_plugin, - python_scripts, - python_current_script, - &weechat_python_api_buffer_input_data_cb, - &weechat_python_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_python_load_cb: callback for script_auto_load() function - */ - -void -weechat_python_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_python_load (filename); -} - -/* - * weechat_python_unload: unload a Python script - */ - -void -weechat_python_unload (struct t_plugin_script *script) -{ - int *rc; - void *interpreter; - PyThreadState *old_interpreter; - - if ((weechat_python_plugin->debug >= 2) || !python_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - PYTHON_PLUGIN_NAME, script->name); - } - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *) weechat_python_exec (script, WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, NULL, NULL); - if (rc) - free (rc); - } - - old_interpreter = PyThreadState_Swap (NULL); - interpreter = script->interpreter; - - if (python_current_script == script) - python_current_script = (python_current_script->prev_script) ? - python_current_script->prev_script : python_current_script->next_script; - - script_remove (weechat_python_plugin, &python_scripts, &last_python_script, - script); - - if (interpreter) - { - PyThreadState_Swap (interpreter); - Py_EndInterpreter (interpreter); - } - - if (old_interpreter) - PyThreadState_Swap (old_interpreter); -} - -/* - * weechat_python_unload_name: unload a Python script by name - */ - -void -weechat_python_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_python_plugin, python_scripts, name); - if (ptr_script) - { - weechat_python_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - PYTHON_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, name); - } -} - -/* - * weechat_python_unload_all: unload all Python scripts - */ - -void -weechat_python_unload_all () -{ - while (python_scripts) - { - weechat_python_unload (python_scripts); - } -} - -/* - * weechat_python_reload_name: reload a Python script by name - */ - -void -weechat_python_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_python_plugin, python_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_python_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - PYTHON_PLUGIN_NAME, name); - weechat_python_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, name); - } -} - -/* - * weechat_python_cmd: callback for "/python" command - */ - -int -weechat_python_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_python_plugin, python_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_python_plugin, python_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_python_plugin, python_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_python_plugin, &weechat_python_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_python_unload_all (); - script_auto_load (weechat_python_plugin, &weechat_python_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_python_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_python_plugin, python_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_python_plugin, python_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Python script */ - path_script = script_search_path (weechat_python_plugin, - argv_eol[2]); - weechat_python_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Python script */ - weechat_python_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Python script */ - weechat_python_unload_name (argv_eol[2]); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME, - "python"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_python_completion_cb: callback for script completion - */ - -int -weechat_python_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_python_plugin, completion, python_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_python_info_cb: callback for info - */ - -const char * -weechat_python_info_cb (void *data, const char *info_name, - const char *arguments) -{ - int rc; - struct stat stat_buf; - - /* make C compiler happy */ - (void) data; - (void) arguments; - - if (weechat_strcasecmp (info_name, "python2_bin") == 0) - { - if (python2_bin && (strcmp (python2_bin, "python") != 0)) - { - rc = stat (python2_bin, &stat_buf); - if ((rc != 0) || (!S_ISREG(stat_buf.st_mode))) - { - free (python2_bin); - weechat_python_set_python2_bin (); - } - } - return python2_bin; - } - - return NULL; -} - -/* - * weechat_python_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_python_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "python_script") == 0) - { - return script_infolist_list_scripts (weechat_python_plugin, - python_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_python_signal_debug_dump_cb: dump Python plugin data in WeeChat log - * file - */ - -int -weechat_python_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, PYTHON_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_python_plugin, python_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_python_signal_buffer_closed_cb: callback called when a buffer is - * closed - */ - -int -weechat_python_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (python_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_python_timer_action_cb: timer for executing actions - */ - -int -weechat_python_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &python_action_install_list) - { - script_action_install (weechat_python_plugin, - python_scripts, - &weechat_python_unload, - &weechat_python_load, - &python_action_install_list); - } - else if (data == &python_action_remove_list) - { - script_action_remove (weechat_python_plugin, - python_scripts, - &weechat_python_unload, - &python_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_python_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_python_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "python_script_install") == 0) - { - script_action_add (&python_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_python_timer_action_cb, - &python_action_install_list); - } - else if (strcmp (signal, "python_script_remove") == 0) - { - script_action_add (&python_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_python_timer_action_cb, - &python_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_init: initialize Python plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; - - weechat_python_plugin = plugin; - - /* - * hook info to get path to python 2.x interpreter - * (some scripts using hook_process need that) - */ - weechat_python_set_python2_bin (); - weechat_hook_info ("python2_bin", - N_("path to python 2.x interpreter"), - NULL, - &weechat_python_info_cb, NULL); - - /* init stdout/stderr buffer */ - python_buffer_output[0] = '\0'; - - PyImport_AppendInittab("weechat", - &weechat_python_init_module_weechat); - - Py_Initialize (); - if (Py_IsInitialized () == 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to launch global " - "interpreter"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - return WEECHAT_RC_ERROR; - } - - /* PyEval_InitThreads(); */ - /* python_mainThreadState = PyThreadState_Swap(NULL); */ - python_mainThreadState = PyEval_SaveThread(); - /* PyEval_ReleaseLock (); */ - - if (!python_mainThreadState) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to get current " - "interpreter state"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - return WEECHAT_RC_ERROR; - } - - init.callback_command = &weechat_python_command_cb; - init.callback_completion = &weechat_python_completion_cb; - init.callback_infolist = &weechat_python_infolist_cb; - init.callback_signal_debug_dump = &weechat_python_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_python_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_python_signal_script_action_cb; - init.callback_load_file = &weechat_python_load_cb; - - python_quiet = 1; - script_init (weechat_python_plugin, argc, argv, &init); - python_quiet = 0; - - script_display_short_list (weechat_python_plugin, - python_scripts); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: shutdown Python interface - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - python_quiet = 1; - script_end (plugin, &python_scripts, &weechat_python_unload_all); - python_quiet = 0; - - /* free Python interpreter */ - if (python_mainThreadState != NULL) - { - /* PyEval_AcquireLock (); */ - PyThreadState_Swap (python_mainThreadState); - /* PyEval_ReleaseLock (); */ - python_mainThreadState = NULL; - } - - Py_Finalize (); - if (Py_IsInitialized () != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to free interpreter"), - weechat_prefix ("error"), PYTHON_PLUGIN_NAME); - } - - /* free some data */ - if (python2_bin) - free (python2_bin); - if (python_action_install_list) - free (python_action_install_list); - if (python_action_remove_list) - free (python_action_remove_list); - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/python/weechat-python.h b/src/plugins/scripts/python/weechat-python.h deleted file mode 100644 index 1a522603a..000000000 --- a/src/plugins/scripts/python/weechat-python.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_PYTHON_H -#define __WEECHAT_PYTHON_H 1 - -#define weechat_plugin weechat_python_plugin -#define PYTHON_PLUGIN_NAME "python" - -#define PYTHON_CURRENT_SCRIPT_NAME ((python_current_script) ? python_current_script->name : "-") - -/* define some bytes functions for old python (<= 2.5) */ -#if PY_VERSION_HEX < 0x02060000 -#define PyBytes_AsString PyString_AsString -#define PyBytes_Check PyString_Check -#define PyBytes_FromString PyString_FromString -#define PyUnicode_FromString PyString_FromString -#endif - -extern struct t_weechat_plugin *weechat_python_plugin; - -extern int python_quiet; -extern struct t_plugin_script *python_scripts; -extern struct t_plugin_script *last_python_script; -extern struct t_plugin_script *python_current_script; -extern struct t_plugin_script *python_registered_script; -extern const char *python_current_script_filename; - -extern PyObject *weechat_python_hashtable_to_dict (struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_python_dict_to_hashtable (PyObject *dict, - int hashtable_size); -extern void *weechat_python_exec (struct t_plugin_script *script, - int ret_type, const char *function, - char *format, void **argv); - -#endif /* __WEECHAT_PYTHON_H */ diff --git a/src/plugins/scripts/ruby/CMakeLists.txt b/src/plugins/scripts/ruby/CMakeLists.txt deleted file mode 100644 index ee69844d5..000000000 --- a/src/plugins/scripts/ruby/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(ruby MODULE weechat-ruby.c weechat-ruby.h weechat-ruby-api.c -weechat-ruby-api.h) - -SET_TARGET_PROPERTIES(ruby PROPERTIES PREFIX "") - -IF(RUBY_FOUND) - INCLUDE_DIRECTORIES(${RUBY_INCLUDE_PATH} ${RUBY_ARCH}) - TARGET_LINK_LIBRARIES(ruby ${RUBY_LIBRARY} weechat_scripts) -ENDIF(RUBY_FOUND) - -INSTALL(TARGETS ruby LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/ruby/Makefile.am b/src/plugins/scripts/ruby/Makefile.am deleted file mode 100644 index dedb40944..000000000 --- a/src/plugins/scripts/ruby/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(RUBY_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = ruby.la - -ruby_la_SOURCES = weechat-ruby.c \ - weechat-ruby.h \ - weechat-ruby-api.c \ - weechat-ruby-api.h -ruby_la_LDFLAGS = -module -ruby_la_LIBADD = ../lib_weechat_plugins_scripts.la $(RUBY_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c deleted file mode 100644 index 6c5aadaa6..000000000 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ /dev/null @@ -1,6864 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-ruby-api.c: ruby API functions - */ - -#undef _ - -#include <ruby.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-ruby.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *ruby_function_name = __name; \ - (void) class; \ - if (__init \ - && (!ruby_current_script || !ruby_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, \ - ruby_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, \ - ruby_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_ruby_plugin, RUBY_CURRENT_SCRIPT_NAME, \ - ruby_function_name, __string) -#define API_RETURN_OK return INT2FIX (1); -#define API_RETURN_ERROR return INT2FIX (0); -#define API_RETURN_EMPTY return Qnil; -#define API_RETURN_STRING(__string) \ - if (__string) \ - return rb_str_new2 (__string); \ - return rb_str_new2 ("") -#define API_RETURN_STRING_FREE(__string) \ - if (__string) \ - { \ - return_value = rb_str_new2 (__string); \ - free (__string); \ - return return_value; \ - } \ - return rb_str_new2 ("") -#define API_RETURN_INT(__int) \ - return INT2FIX (__int); -#define API_RETURN_LONG(__long) \ - return LONG2FIX (__long); - -#define API_DEF_FUNC(__name, __argc) \ - rb_define_module_function (ruby_mWeechat, #__name, \ - &weechat_ruby_api_##__name, __argc); - - -/* - * weechat_ruby_api_register: startup function for all WeeChat Ruby scripts - */ - -static VALUE -weechat_ruby_api_register (VALUE class, VALUE name, VALUE author, - VALUE version, VALUE license, VALUE description, - VALUE shutdown_func, VALUE charset) -{ - char *c_name, *c_author, *c_version, *c_license, *c_description; - char *c_shutdown_func, *c_charset; - - API_FUNC(0, "register", API_RETURN_ERROR); - if (ruby_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - ruby_registered_script->name); - API_RETURN_ERROR; - } - ruby_current_script = NULL; - ruby_registered_script = NULL; - if (NIL_P (name) || NIL_P (author) || NIL_P (version) - || NIL_P (license) || NIL_P (description) || NIL_P (shutdown_func) - || NIL_P (charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (name, T_STRING); - Check_Type (author, T_STRING); - Check_Type (version, T_STRING); - Check_Type (license, T_STRING); - Check_Type (description, T_STRING); - Check_Type (shutdown_func, T_STRING); - Check_Type (charset, T_STRING); - - c_name = StringValuePtr (name); - c_author = StringValuePtr (author); - c_version = StringValuePtr (version); - c_license = StringValuePtr (license); - c_description = StringValuePtr (description); - c_shutdown_func = StringValuePtr (shutdown_func); - c_charset = StringValuePtr (charset); - - if (script_search (weechat_ruby_plugin, ruby_scripts, c_name)) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, c_name); - API_RETURN_ERROR; - } - - /* register script */ - ruby_current_script = script_add (weechat_ruby_plugin, - &ruby_scripts, &last_ruby_script, - (ruby_current_script_filename) ? - ruby_current_script_filename : "", - c_name, c_author, c_version, c_license, - c_description, c_shutdown_func, - c_charset); - - if (ruby_current_script) - { - ruby_registered_script = ruby_current_script; - if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - RUBY_PLUGIN_NAME, c_name, c_version, c_description); - } - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_plugin_get_name: get name of plugin (return "core" for - * WeeChat core) - */ - -static VALUE -weechat_ruby_api_plugin_get_name (VALUE class, VALUE plugin) -{ - char *c_plugin; - const char *result; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - if (NIL_P (plugin)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (plugin, T_STRING); - - c_plugin = StringValuePtr (plugin); - - result = weechat_plugin_get_name (API_STR2PTR(c_plugin)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_charset_set: set script charset - */ - -static VALUE -weechat_ruby_api_charset_set (VALUE class, VALUE charset) -{ - char *c_charset; - - API_FUNC(1, "charset_set", API_RETURN_ERROR); - if (NIL_P (charset)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (charset, T_STRING); - - c_charset = StringValuePtr (charset); - - script_api_charset_set (ruby_current_script, c_charset); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_iconv_to_internal: convert string to internal WeeChat charset - */ - -static VALUE -weechat_ruby_api_iconv_to_internal (VALUE class, VALUE charset, VALUE string) -{ - char *c_charset, *c_string, *result; - VALUE return_value; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - if (NIL_P (charset) || NIL_P (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (charset, T_STRING); - Check_Type (string, T_STRING); - - c_charset = StringValuePtr (charset); - c_string = StringValuePtr (string); - - result = weechat_iconv_to_internal (c_charset, c_string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_iconv_from_internal: convert string from WeeChat internal - * charset to another one - */ - -static VALUE -weechat_ruby_api_iconv_from_internal (VALUE class, VALUE charset, VALUE string) -{ - char *c_charset, *c_string, *result; - VALUE return_value; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - if (NIL_P (charset) || NIL_P (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (charset, T_STRING); - Check_Type (string, T_STRING); - - c_charset = StringValuePtr (charset); - c_string = StringValuePtr (string); - - result = weechat_iconv_from_internal (c_charset, c_string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_gettext: get translated string - */ - -static VALUE -weechat_ruby_api_gettext (VALUE class, VALUE string) -{ - char *c_string; - const char *result; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - if (NIL_P (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (string, T_STRING); - - c_string = StringValuePtr (string); - - result = weechat_gettext (c_string); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_ngettext: get translated string with plural form - */ - -static VALUE -weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural, - VALUE count) -{ - char *c_single, *c_plural; - const char *result; - int c_count; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - if (NIL_P (single) || NIL_P (plural) || NIL_P (count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (single, T_STRING); - Check_Type (plural, T_STRING); - Check_Type (count, T_FIXNUM); - - c_single = StringValuePtr (single); - c_plural = StringValuePtr (plural); - c_count = FIX2INT (count); - - result = weechat_ngettext (c_single, c_plural, c_count); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other "*" - * are allowed inside mask - */ - -static VALUE -weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask, - VALUE case_sensitive) -{ - char *c_string, *c_mask; - int c_case_sensitive, value; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - if (NIL_P (string) || NIL_P (mask) || NIL_P (case_sensitive)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (string, T_STRING); - Check_Type (mask, T_STRING); - Check_Type (case_sensitive, T_FIXNUM); - - c_string = StringValuePtr (string); - c_mask = StringValuePtr (mask); - c_case_sensitive = FIX2INT (case_sensitive); - - value = weechat_string_match (c_string, c_mask, c_case_sensitive); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_string_has_highlight: return 1 if string contains a - * highlight (using list of words to - * highlight) - * return 0 if no highlight is found in - * string - */ - -static VALUE -weechat_ruby_api_string_has_highlight (VALUE class, VALUE string, - VALUE highlight_words) -{ - char *c_string, *c_highlight_words; - int value; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - if (NIL_P (string) || NIL_P (highlight_words)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (string, T_STRING); - Check_Type (highlight_words, T_STRING); - - c_string = StringValuePtr (string); - c_highlight_words = StringValuePtr (highlight_words); - - value = weechat_string_has_highlight (c_string, c_highlight_words); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_string_has_highlight_regex: return 1 if string contains a - * highlight (using regular - * expression) - * return 0 if no highlight is - * found in string - */ - -static VALUE -weechat_ruby_api_string_has_highlight_regex (VALUE class, VALUE string, - VALUE regex) -{ - char *c_string, *c_regex; - int value; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - if (NIL_P (string) || NIL_P (regex)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (string, T_STRING); - Check_Type (regex, T_STRING); - - c_string = StringValuePtr (string); - c_regex = StringValuePtr (regex); - - value = weechat_string_has_highlight_regex (c_string, c_regex); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_string_mask_to_regex: convert a mask (string with only - * "*" as wildcard) to a regex, paying - * attention to special chars in a - * regex - */ - -static VALUE -weechat_ruby_api_string_mask_to_regex (VALUE class, VALUE mask) -{ - char *c_mask, *result; - VALUE return_value; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - if (NIL_P (mask)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (mask, T_STRING); - - c_mask = StringValuePtr (mask); - - result = weechat_string_mask_to_regex (c_mask); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_string_remove_color: remove WeeChat color codes from string - */ - -static VALUE -weechat_ruby_api_string_remove_color (VALUE class, VALUE string, - VALUE replacement) -{ - char *c_string, *c_replacement, *result; - VALUE return_value; - - API_FUNC(1, "string_remove_color", API_RETURN_EMPTY); - if (NIL_P (string) || NIL_P (replacement)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (string, T_STRING); - Check_Type (replacement, T_STRING); - - c_string = StringValuePtr (string); - c_replacement = StringValuePtr (replacement); - - result = weechat_string_remove_color (c_string, c_replacement); - - API_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; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - if (NIL_P (string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (string, T_STRING); - - c_string = StringValuePtr (string); - - value = weechat_string_is_command_char (c_string); - - API_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; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - if (NIL_P (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (string, T_STRING); - - c_string = StringValuePtr (string); - - result = weechat_string_input_for_buffer (c_string); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_mkdir_home: create a directory in WeeChat home - */ - -static VALUE -weechat_ruby_api_mkdir_home (VALUE class, VALUE directory, VALUE mode) -{ - char *c_directory; - int c_mode; - - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - if (NIL_P (directory) || NIL_P (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (directory, T_STRING); - Check_Type (mode, T_FIXNUM); - - c_directory = StringValuePtr (directory); - c_mode = FIX2INT (mode); - - if (weechat_mkdir_home (c_directory, c_mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_ruby_api_mkdir: create a directory - */ - -static VALUE -weechat_ruby_api_mkdir (VALUE class, VALUE directory, VALUE mode) -{ - char *c_directory; - int c_mode; - - API_FUNC(1, "mkdir", API_RETURN_ERROR); - if (NIL_P (directory) || NIL_P (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (directory, T_STRING); - Check_Type (mode, T_FIXNUM); - - c_directory = StringValuePtr (directory); - c_mode = FIX2INT (mode); - - if (weechat_mkdir (c_directory, c_mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_ruby_api_mkdir_parents: create a directory and make parent - * directories as needed - */ - -static VALUE -weechat_ruby_api_mkdir_parents (VALUE class, VALUE directory, VALUE mode) -{ - char *c_directory; - int c_mode; - - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - if (NIL_P (directory) || NIL_P (mode)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (directory, T_STRING); - Check_Type (mode, T_FIXNUM); - - c_directory = StringValuePtr (directory); - c_mode = FIX2INT (mode); - - if (weechat_mkdir_parents (c_directory, c_mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_ruby_api_list_new: create a new list - */ - -static VALUE -weechat_ruby_api_list_new (VALUE class) -{ - char *result; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_add: add a string to list - */ - -static VALUE -weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where, - VALUE user_data) -{ - char *c_weelist, *c_data, *c_where, *c_user_data, *result; - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - if (NIL_P (weelist) || NIL_P (data) || NIL_P (where) || NIL_P (user_data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (weelist, T_STRING); - Check_Type (data, T_STRING); - Check_Type (where, T_STRING); - Check_Type (user_data, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_data = StringValuePtr (data); - c_where = StringValuePtr (where); - c_user_data = StringValuePtr (user_data); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(c_weelist), - c_data, - c_where, - API_STR2PTR(c_user_data))); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_search: search a string in list - */ - -static VALUE -weechat_ruby_api_list_search (VALUE class, VALUE weelist, VALUE data) -{ - char *c_weelist, *c_data, *result; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - if (NIL_P (weelist) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (weelist, T_STRING); - Check_Type (data, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_data = StringValuePtr (data); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(c_weelist), - c_data)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_search_pos: search position of a string in list - */ - -static VALUE -weechat_ruby_api_list_search_pos (VALUE class, VALUE weelist, VALUE data) -{ - char *c_weelist, *c_data; - int pos; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - if (NIL_P (weelist) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (weelist, T_STRING); - Check_Type (data, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_data = StringValuePtr (data); - - pos = weechat_list_search_pos (API_STR2PTR(c_weelist), c_data); - - API_RETURN_INT(pos); -} - -/* - * weechat_ruby_api_list_casesearch: search a string in list (ignore case) - */ - -static VALUE -weechat_ruby_api_list_casesearch (VALUE class, VALUE weelist, VALUE data) -{ - char *c_weelist, *c_data, *result; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - if (NIL_P (weelist) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (weelist, T_STRING); - Check_Type (data, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_data = StringValuePtr (data); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(c_weelist), - c_data)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -static VALUE -weechat_ruby_api_list_casesearch_pos (VALUE class, VALUE weelist, VALUE data) -{ - char *c_weelist, *c_data; - int pos; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - if (NIL_P (weelist) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (weelist, T_STRING); - Check_Type (data, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_data = StringValuePtr (data); - - pos = weechat_list_casesearch_pos (API_STR2PTR(c_weelist), c_data); - - API_RETURN_INT(pos); -} - -/* - * weechat_ruby_api_list_get: get item by position - */ - -static VALUE -weechat_ruby_api_list_get (VALUE class, VALUE weelist, VALUE position) -{ - char *c_weelist, *result; - int c_position; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - if (NIL_P (weelist) || NIL_P (position)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (weelist, T_STRING); - Check_Type (position, T_FIXNUM); - - c_weelist = StringValuePtr (weelist); - c_position = FIX2INT (position); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(c_weelist), - c_position)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_set: set new value for item - */ - -static VALUE -weechat_ruby_api_list_set (VALUE class, VALUE item, VALUE new_value) -{ - char *c_item, *c_new_value; - - API_FUNC(1, "list_set", API_RETURN_ERROR); - if (NIL_P (item) || NIL_P (new_value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (item, T_STRING); - Check_Type (new_value, T_STRING); - - c_item = StringValuePtr (item); - c_new_value = StringValuePtr (new_value); - - weechat_list_set (API_STR2PTR(c_item), - c_new_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_list_next: get next item - */ - -static VALUE -weechat_ruby_api_list_next (VALUE class, VALUE item) -{ - char *c_item, *result; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - if (NIL_P (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (item, T_STRING); - - c_item = StringValuePtr (item); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(c_item))); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_prev: get previous item - */ - -static VALUE -weechat_ruby_api_list_prev (VALUE class, VALUE item) -{ - char *c_item, *result; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - if (NIL_P (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (item, T_STRING); - - c_item = StringValuePtr (item); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(c_item))); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_string: get string value of item - */ - -static VALUE -weechat_ruby_api_list_string (VALUE class, VALUE item) -{ - char *c_item; - const char *result; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - if (NIL_P (item)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (item, T_STRING); - - c_item = StringValuePtr (item); - - result = weechat_list_string (API_STR2PTR(c_item)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_list_size: get number of elements in list - */ - -static VALUE -weechat_ruby_api_list_size (VALUE class, VALUE weelist) -{ - char *c_weelist; - int size; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - if (NIL_P (weelist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (weelist, T_STRING); - - c_weelist = StringValuePtr (weelist); - - size = weechat_list_size (API_STR2PTR(c_weelist)); - - API_RETURN_INT(size); -} - -/* - * weechat_ruby_api_list_remove: remove item from list - */ - -static VALUE -weechat_ruby_api_list_remove (VALUE class, VALUE weelist, VALUE item) -{ - char *c_weelist, *c_item; - - API_FUNC(1, "list_remove", API_RETURN_ERROR); - if (NIL_P (weelist) || NIL_P (item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (weelist, T_STRING); - Check_Type (item, T_STRING); - - c_weelist = StringValuePtr (weelist); - c_item = StringValuePtr (item); - - weechat_list_remove (API_STR2PTR(c_weelist), - API_STR2PTR(c_item)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_list_remove_all: remove all items from list - */ - -static VALUE -weechat_ruby_api_list_remove_all (VALUE class, VALUE weelist) -{ - char *c_weelist; - - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - if (NIL_P (weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (weelist, T_STRING); - - c_weelist = StringValuePtr (weelist); - - weechat_list_remove_all (API_STR2PTR(c_weelist)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_list_free: free list - */ - -static VALUE -weechat_ruby_api_list_free (VALUE class, VALUE weelist) -{ - char *c_weelist; - - API_FUNC(1, "list_free", API_RETURN_ERROR); - if (NIL_P (weelist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (weelist, T_STRING); - - c_weelist = StringValuePtr (weelist); - - weechat_list_free (API_STR2PTR(c_weelist)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_reload_cb: callback for config reload - */ - -int -weechat_ruby_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat_ruby_api_config_new: create a new configuration file - */ - -static VALUE -weechat_ruby_api_config_new (VALUE class, VALUE name, VALUE function, - VALUE data) -{ - char *c_name, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - if (NIL_P (name) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_name = StringValuePtr (name); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_config_new (weechat_ruby_plugin, - ruby_current_script, - c_name, - &weechat_ruby_api_config_reload_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_read_cb: callback for reading option in section - */ - -int -weechat_ruby_api_config_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_ruby_api_config_section_write_cb: callback for writing section - */ - -int -weechat_ruby_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_ruby_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_ruby_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_ruby_api_config_section_create_option_cb: callback to create an option - */ - -int -weechat_ruby_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_ruby_api_config_section_delete_option_cb: callback to delete an option - */ - -int -weechat_ruby_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat_ruby_api_config_new_section: create a new section in configuration file - */ - -static VALUE -weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, - VALUE name, VALUE user_can_add_options, - VALUE user_can_delete_options, - VALUE function_read, - VALUE data_read, - VALUE function_write, - VALUE data_write, - VALUE function_write_default, - VALUE data_write_default, - VALUE function_create_option, - VALUE data_create_option, - VALUE function_delete_option, - VALUE data_delete_option) -{ - char *c_config_file, *c_name, *c_function_read, *c_data_read; - char *c_function_write, *c_data_write, *c_function_write_default; - char *c_data_write_default, *c_function_create_option; - char *c_data_create_option, *c_function_delete_option; - char *c_data_delete_option, *result; - int c_user_can_add_options, c_user_can_delete_options; - VALUE return_value; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - if (NIL_P (config_file) || NIL_P (name) || NIL_P (user_can_add_options) - || NIL_P (user_can_delete_options) || NIL_P (function_read) - || NIL_P (data_read) || NIL_P (function_write) || NIL_P (data_write) - || NIL_P (function_write_default) || NIL_P (data_write_default) - || NIL_P (function_create_option) || NIL_P (data_create_option) - || NIL_P (function_delete_option) || NIL_P (data_delete_option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (config_file, T_STRING); - Check_Type (name, T_STRING); - Check_Type (user_can_add_options, T_FIXNUM); - Check_Type (user_can_delete_options, T_FIXNUM); - Check_Type (function_read, T_STRING); - Check_Type (data_read, T_STRING); - Check_Type (function_write, T_STRING); - Check_Type (data_write, T_STRING); - Check_Type (function_write_default, T_STRING); - Check_Type (data_write_default, T_STRING); - Check_Type (function_create_option, T_STRING); - Check_Type (data_create_option, T_STRING); - Check_Type (function_delete_option, T_STRING); - Check_Type (data_delete_option, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_name = StringValuePtr (name); - c_user_can_add_options = FIX2INT (user_can_add_options); - c_user_can_delete_options = FIX2INT (user_can_delete_options); - c_function_read = StringValuePtr (function_read); - c_data_read = StringValuePtr (data_read); - c_function_write = StringValuePtr (function_write); - c_data_write = StringValuePtr (data_write); - c_function_write_default = StringValuePtr (function_write_default); - c_data_write_default = StringValuePtr (data_write_default); - c_function_create_option = StringValuePtr (function_create_option); - c_data_create_option = StringValuePtr (data_create_option); - c_function_delete_option = StringValuePtr (function_delete_option); - c_data_delete_option = StringValuePtr (data_delete_option); - - result = script_ptr2str (script_api_config_new_section (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_config_file), - c_name, - c_user_can_add_options, - c_user_can_delete_options, - &weechat_ruby_api_config_read_cb, - c_function_read, - c_data_read, - &weechat_ruby_api_config_section_write_cb, - c_function_write, - c_data_write, - &weechat_ruby_api_config_section_write_default_cb, - c_function_write_default, - c_data_write_default, - &weechat_ruby_api_config_section_create_option_cb, - c_function_create_option, - c_data_create_option, - &weechat_ruby_api_config_section_delete_option_cb, - c_function_delete_option, - c_data_delete_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_search_section: search section in configuration file - */ - -static VALUE -weechat_ruby_api_config_search_section (VALUE class, VALUE config_file, - VALUE section_name) -{ - char *c_config_file, *c_section_name, *result; - VALUE return_value; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - if (NIL_P (config_file) || NIL_P (section_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (config_file, T_STRING); - Check_Type (section_name, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_section_name = StringValuePtr (section_name); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(c_config_file), - c_section_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_option_check_value_cb: callback for checking new - * value for option - */ - -int -weechat_ruby_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_ruby_api_config_option_change_cb: callback for option changed - */ - -void -weechat_ruby_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_ruby_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_ruby_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_ruby_api_config_new_option: create a new option in section - */ - -static VALUE -weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, - VALUE section, VALUE name, VALUE type, - VALUE description, VALUE string_values, - VALUE min, VALUE max, VALUE default_value, - VALUE value, VALUE null_value_allowed, - VALUE function_check_value, - VALUE data_check_value, - VALUE function_change, - VALUE data_change, - VALUE function_delete, - VALUE data_delete) -{ - char *c_config_file, *c_section, *c_name, *c_type, *c_description; - char *c_string_values, *c_default_value, *c_value; - char *c_function_check_value, *c_data_check_value, *c_function_change; - char *c_data_change, *c_function_delete, *c_data_delete, *result; - int c_min, c_max, c_null_value_allowed; - VALUE return_value; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - if (NIL_P (config_file) || NIL_P (section) || NIL_P (name) || NIL_P (type) - || NIL_P (description) || NIL_P (string_values) || NIL_P (min) - || NIL_P (max) || NIL_P (default_value) || NIL_P (value) - || NIL_P (null_value_allowed) || NIL_P (function_check_value) - || NIL_P (data_check_value) || NIL_P (function_change) - || NIL_P (data_change) || NIL_P (function_delete) - || NIL_P (data_delete)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (config_file, T_STRING); - Check_Type (section, T_STRING); - Check_Type (name, T_STRING); - Check_Type (type, T_STRING); - Check_Type (description, T_STRING); - Check_Type (string_values, T_STRING); - Check_Type (min, T_FIXNUM); - Check_Type (max, T_FIXNUM); - Check_Type (default_value, T_STRING); - Check_Type (value, T_STRING); - Check_Type (null_value_allowed, T_FIXNUM); - Check_Type (function_check_value, T_STRING); - Check_Type (data_check_value, T_STRING); - Check_Type (function_change, T_STRING); - Check_Type (data_change, T_STRING); - Check_Type (function_delete, T_STRING); - Check_Type (data_delete, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_section = StringValuePtr (section); - c_name = StringValuePtr (name); - c_type = StringValuePtr (type); - c_description = StringValuePtr (description); - c_string_values = StringValuePtr (string_values); - c_min = FIX2INT (min); - c_max = FIX2INT (max); - c_default_value = StringValuePtr (default_value); - c_value = StringValuePtr (value); - c_null_value_allowed = FIX2INT (null_value_allowed); - c_function_check_value = StringValuePtr (function_check_value); - c_data_check_value = StringValuePtr (data_check_value); - c_function_change = StringValuePtr (function_change); - c_data_change = StringValuePtr (data_change); - c_function_delete = StringValuePtr (function_delete); - c_data_delete = StringValuePtr (data_delete); - - result = script_ptr2str (script_api_config_new_option (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_config_file), - API_STR2PTR(c_section), - c_name, - c_type, - c_description, - c_string_values, - c_min, - c_max, - c_default_value, - c_value, - c_null_value_allowed, - &weechat_ruby_api_config_option_check_value_cb, - c_function_check_value, - c_data_check_value, - &weechat_ruby_api_config_option_change_cb, - c_function_change, - c_data_change, - &weechat_ruby_api_config_option_delete_cb, - c_function_delete, - c_data_delete)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_search_option: search option in configuration file or section - */ - -static VALUE -weechat_ruby_api_config_search_option (VALUE class, VALUE config_file, - VALUE section, VALUE option_name) -{ - char *c_config_file, *c_section, *c_option_name, *result; - VALUE return_value; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - if (NIL_P (config_file) || NIL_P (section) || NIL_P (option_name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (config_file, T_STRING); - Check_Type (section, T_STRING); - Check_Type (option_name, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_section = StringValuePtr (section); - c_option_name = StringValuePtr (option_name); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(c_config_file), - API_STR2PTR(c_section), - c_option_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_string_to_boolean: return boolean value of a string - */ - -static VALUE -weechat_ruby_api_config_string_to_boolean (VALUE class, VALUE text) -{ - char *c_text; - int value; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - if (NIL_P (text)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (text, T_STRING); - - c_text = StringValuePtr (text); - - value = weechat_config_string_to_boolean (c_text); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_option_reset: reset option with default value - */ - -static VALUE -weechat_ruby_api_config_option_reset (VALUE class, VALUE option, - VALUE run_callback) -{ - char *c_option; - int c_run_callback, rc; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - if (NIL_P (option) || NIL_P (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - Check_Type (run_callback, T_FIXNUM); - - c_option = StringValuePtr (option); - c_run_callback = FIX2INT (run_callback); - - rc = weechat_config_option_reset (API_STR2PTR(c_option), - c_run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_option_set: set new value for option - */ - -static VALUE -weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value, - VALUE run_callback) -{ - char *c_option, *c_new_value; - int c_run_callback, rc; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (NIL_P (option) || NIL_P (new_value) || NIL_P (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - Check_Type (option, T_STRING); - Check_Type (new_value, T_STRING); - Check_Type (run_callback, T_FIXNUM); - - c_option = StringValuePtr (option); - c_new_value = StringValuePtr (new_value); - c_run_callback = FIX2INT (run_callback); - - rc = weechat_config_option_set (API_STR2PTR(c_option), - c_new_value, - c_run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_option_set_null: set null (undefined) value for - * option - */ - -static VALUE -weechat_ruby_api_config_option_set_null (VALUE class, VALUE option, - VALUE run_callback) -{ - char *c_option; - int c_run_callback, rc; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (NIL_P (option) || NIL_P (run_callback)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - Check_Type (option, T_STRING); - Check_Type (run_callback, T_FIXNUM); - - c_option = StringValuePtr (option); - c_run_callback = FIX2INT (run_callback); - - rc = weechat_config_option_set_null (API_STR2PTR(c_option), - c_run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_option_unset: unset an option - */ - -static VALUE -weechat_ruby_api_config_option_unset (VALUE class, VALUE option) -{ - char *c_option; - int rc; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - rc = weechat_config_option_unset (API_STR2PTR(c_option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_option_rename: rename an option - */ - -static VALUE -weechat_ruby_api_config_option_rename (VALUE class, VALUE option, - VALUE new_name) -{ - char *c_option, *c_new_name; - - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - if (NIL_P (option) || NIL_P (new_name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (option, T_STRING); - Check_Type (new_name, T_STRING); - - c_option = StringValuePtr (option); - c_new_name = StringValuePtr (new_name); - - weechat_config_option_rename (API_STR2PTR(c_option), - c_new_name); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_option_is_null: return 1 if value of option is null - */ - -static VALUE -weechat_ruby_api_config_option_is_null (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_option_is_null (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_option_default_is_null: return 1 if value of option is null - */ - -static VALUE -weechat_ruby_api_config_option_default_is_null (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(1)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_option_default_is_null (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_boolean: return boolean value of option - */ - -static VALUE -weechat_ruby_api_config_boolean (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_boolean (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_boolean_default: return default boolean value of option - */ - -static VALUE -weechat_ruby_api_config_boolean_default (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_boolean_default (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_integer: return integer value of option - */ - -static VALUE -weechat_ruby_api_config_integer (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_integer (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_integer_default: return default integer value of option - */ - -static VALUE -weechat_ruby_api_config_integer_default (VALUE class, VALUE option) -{ - char *c_option; - int value; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - value = weechat_config_integer_default (API_STR2PTR(c_option)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_config_string: return string value of option - */ - -static VALUE -weechat_ruby_api_config_string (VALUE class, VALUE option) -{ - char *c_option; - const char *result; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = weechat_config_string (API_STR2PTR(c_option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_config_string_default: return default string value of option - */ - -static VALUE -weechat_ruby_api_config_string_default (VALUE class, VALUE option) -{ - char *c_option; - const char *result; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = weechat_config_string_default (API_STR2PTR(c_option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_config_color: return color value of option - */ - -static VALUE -weechat_ruby_api_config_color (VALUE class, VALUE option) -{ - char *c_option; - const char *result; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = weechat_config_color (API_STR2PTR(c_option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_config_color_default: return default color value of option - */ - -static VALUE -weechat_ruby_api_config_color_default (VALUE class, VALUE option) -{ - char *c_option; - const char *result; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = weechat_config_color_default (API_STR2PTR(c_option)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_config_write_option: write an option in configuration file - */ - -static VALUE -weechat_ruby_api_config_write_option (VALUE class, VALUE config_file, - VALUE option) -{ - char *c_config_file, *c_option; - - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - if (NIL_P (config_file) || NIL_P (option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (config_file, T_STRING); - Check_Type (option, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_option = StringValuePtr (option); - - weechat_config_write_option (API_STR2PTR(c_config_file), - API_STR2PTR(c_option)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_write_line: write a line in configuration file - */ - -static VALUE -weechat_ruby_api_config_write_line (VALUE class, VALUE config_file, - VALUE option_name, VALUE value) -{ - char *c_config_file, *c_option_name, *c_value; - - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - if (NIL_P (config_file) || NIL_P (option_name) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (config_file, T_STRING); - Check_Type (option_name, T_STRING); - Check_Type (value, T_STRING); - - c_config_file = StringValuePtr (config_file); - c_option_name = StringValuePtr (option_name); - c_value = StringValuePtr (value); - - weechat_config_write_line (API_STR2PTR(c_config_file), - c_option_name, - "%s", - c_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_write: write configuration file - */ - -static VALUE -weechat_ruby_api_config_write (VALUE class, VALUE config_file) -{ - char *c_config_file; - int rc; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - if (NIL_P (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (config_file, T_STRING); - - c_config_file = StringValuePtr (config_file); - - rc = weechat_config_write (API_STR2PTR(c_config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_read: read configuration file - */ - -static VALUE -weechat_ruby_api_config_read (VALUE class, VALUE config_file) -{ - char *c_config_file; - int rc; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - if (NIL_P (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (config_file, T_STRING); - - c_config_file = StringValuePtr (config_file); - - rc = weechat_config_read (API_STR2PTR(c_config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_reload: reload configuration file - */ - -static VALUE -weechat_ruby_api_config_reload (VALUE class, VALUE config_file) -{ - char *c_config_file; - int rc; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - if (NIL_P (config_file)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (config_file, T_STRING); - - c_config_file = StringValuePtr (config_file); - - rc = weechat_config_reload (API_STR2PTR(c_config_file)); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_option_free: free an option in configuration file - */ - -static VALUE -weechat_ruby_api_config_option_free (VALUE class, VALUE option) -{ - char *c_option; - - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - script_api_config_option_free (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_option)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_section_free_options: free all options of a section - * in configuration file - */ - -static VALUE -weechat_ruby_api_config_section_free_options (VALUE class, VALUE section) -{ - char *c_section; - - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - if (NIL_P (section)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (section, T_STRING); - - c_section = StringValuePtr (section); - - script_api_config_section_free_options (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_section)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_section_free: free section in configuration file - */ - -static VALUE -weechat_ruby_api_config_section_free (VALUE class, VALUE section) -{ - char *c_section; - - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - if (NIL_P (section)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (section, T_STRING); - - c_section = StringValuePtr (section); - - script_api_config_section_free (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_section)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_free: free configuration file - */ - -static VALUE -weechat_ruby_api_config_free (VALUE class, VALUE config_file) -{ - char *c_config_file; - - API_FUNC(1, "config_free", API_RETURN_ERROR); - if (NIL_P (config_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (config_file, T_STRING); - - c_config_file = StringValuePtr (config_file); - - script_api_config_free (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_config_file)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_get: get config option - */ - -static VALUE -weechat_ruby_api_config_get (VALUE class, VALUE option) -{ - char *c_option, *result; - VALUE return_value; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = script_ptr2str (weechat_config_get (c_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_config_get_plugin: get value of a plugin option - */ - -static VALUE -weechat_ruby_api_config_get_plugin (VALUE class, VALUE option) -{ - char *c_option; - const char *result; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - result = script_api_config_get_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_config_is_set_plugin: check if a plugin option is set - */ - -static VALUE -weechat_ruby_api_config_is_set_plugin (VALUE class, VALUE option) -{ - char *c_option; - int rc; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - rc = script_api_config_is_set_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_set_plugin: set value of a plugin option - */ - -static VALUE -weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value) -{ - char *c_option, *c_value; - int rc; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (NIL_P (option) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - Check_Type (option, T_STRING); - Check_Type (value, T_STRING); - - c_option = StringValuePtr (option); - c_value = StringValuePtr (value); - - rc = script_api_config_set_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option, - c_value); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_config_set_desc_plugin: set description of a plugin option - */ - -static VALUE -weechat_ruby_api_config_set_desc_plugin (VALUE class, VALUE option, - VALUE description) -{ - char *c_option, *c_description; - - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - if (NIL_P (option) || NIL_P (description)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (option, T_STRING); - Check_Type (description, T_STRING); - - c_option = StringValuePtr (option); - c_description = StringValuePtr (description); - - script_api_config_set_desc_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option, - c_description); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_config_unset_plugin: unset plugin option - */ - -static VALUE -weechat_ruby_api_config_unset_plugin (VALUE class, VALUE option) -{ - char *c_option; - int rc; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (NIL_P (option)) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - Check_Type (option, T_STRING); - - c_option = StringValuePtr (option); - - rc = script_api_config_unset_plugin (weechat_ruby_plugin, - ruby_current_script, - c_option); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_key_bind: bind key(s) - */ - -static VALUE -weechat_ruby_api_key_bind (VALUE class, VALUE context, VALUE keys) -{ - char *c_context; - struct t_hashtable *c_keys; - int num_keys; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - if (NIL_P (context) || NIL_P (keys)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (context, T_STRING); - Check_Type (keys, T_HASH); - - c_context = StringValuePtr (context); - c_keys = weechat_ruby_hash_to_hashtable (keys, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (c_context, c_keys); - - if (c_keys) - weechat_hashtable_free (c_keys); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_ruby_api_key_unbind: unbind key(s) - */ - -static VALUE -weechat_ruby_api_key_unbind (VALUE class, VALUE context, VALUE key) -{ - char *c_context, *c_key; - int num_keys; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - if (NIL_P (context) || NIL_P (key)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (context, T_STRING); - Check_Type (key, T_STRING); - - c_context = StringValuePtr (context); - c_key = StringValuePtr (key); - - num_keys = weechat_key_unbind (c_context, c_key); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_ruby_api_prefix: get a prefix, used for display - */ - -static VALUE -weechat_ruby_api_prefix (VALUE class, VALUE prefix) -{ - char *c_prefix; - const char *result; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - if (NIL_P (prefix)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (prefix, T_STRING); - - c_prefix = StringValuePtr (prefix); - - result = weechat_prefix (c_prefix); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_color: get a color code, used for display - */ - -static VALUE -weechat_ruby_api_color (VALUE class, VALUE color) -{ - char *c_color; - const char *result; - - API_FUNC(0, "color", API_RETURN_EMPTY); - if (NIL_P (color)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (color, T_STRING); - - c_color = StringValuePtr (color); - - result = weechat_color (c_color); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_print: print message in a buffer - */ - -static VALUE -weechat_ruby_api_print (VALUE class, VALUE buffer, VALUE message) -{ - char *c_buffer, *c_message; - - API_FUNC(0, "print", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (message, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_message = StringValuePtr (message); - - script_api_printf (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer), - "%s", c_message); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_print_date_tags: print message in a buffer with optional - * date and tags - */ - -static VALUE -weechat_ruby_api_print_date_tags (VALUE class, VALUE buffer, VALUE date, - VALUE tags, VALUE message) -{ - char *c_buffer, *c_tags, *c_message; - int c_date; - - API_FUNC(1, "print_date_tags", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (date) || NIL_P (tags) || NIL_P (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (date, T_FIXNUM); - Check_Type (tags, T_STRING); - Check_Type (message, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_date = FIX2INT (date); - c_tags = StringValuePtr (tags); - c_message = StringValuePtr (message); - - script_api_printf_date_tags (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer), - c_date, - c_tags, - "%s", c_message); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_print_y: print message in a buffer with free content - */ - -static VALUE -weechat_ruby_api_print_y (VALUE class, VALUE buffer, VALUE y, VALUE message) -{ - char *c_buffer, *c_message; - int c_y; - - API_FUNC(1, "print_y", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (y) || NIL_P (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (y, T_FIXNUM); - Check_Type (message, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_y = FIX2INT (y); - c_message = StringValuePtr (message); - - script_api_printf_y (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer), - c_y, - "%s", c_message); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_log_print: print message in WeeChat log file - */ - -static VALUE -weechat_ruby_api_log_print (VALUE class, VALUE message) -{ - char *c_message; - - API_FUNC(1, "log_print", API_RETURN_ERROR); - if (NIL_P (message)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (message, T_STRING); - - c_message = StringValuePtr (message); - - script_api_log_printf (weechat_ruby_plugin, - ruby_current_script, - "%s", c_message); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_hook_command_cb: callback for command hooked - */ - -int -weechat_ruby_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_command: hook a command - */ - -static VALUE -weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description, - VALUE args, VALUE args_description, - VALUE completion, VALUE function, VALUE data) -{ - char *c_command, *c_description, *c_args, *c_args_description; - char *c_completion, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - if (NIL_P (command) || NIL_P (description) || NIL_P (args) - || NIL_P (args_description) || NIL_P (completion) || NIL_P (function) - || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (command, T_STRING); - Check_Type (description, T_STRING); - Check_Type (args, T_STRING); - Check_Type (args_description, T_STRING); - Check_Type (completion, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_command = StringValuePtr (command); - c_description = StringValuePtr (description); - c_args = StringValuePtr (args); - c_args_description = StringValuePtr (args_description); - c_completion = StringValuePtr (completion); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_command (weechat_ruby_plugin, - ruby_current_script, - c_command, - c_description, - c_args, - c_args_description, - c_completion, - &weechat_ruby_api_hook_command_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_ruby_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_command_run: hook a command_run - */ - -static VALUE -weechat_ruby_api_hook_command_run (VALUE class, VALUE command, VALUE function, - VALUE data) -{ - char *c_command, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - if (NIL_P (command) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (command, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_command = StringValuePtr (command); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_command_run (weechat_ruby_plugin, - ruby_current_script, - c_command, - &weechat_ruby_api_hook_command_run_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_ruby_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_timer: hook a timer - */ - -static VALUE -weechat_ruby_api_hook_timer (VALUE class, VALUE interval, VALUE align_second, - VALUE max_calls, VALUE function, VALUE data) -{ - int c_interval, c_align_second, c_max_calls; - char *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - if (NIL_P (interval) || NIL_P (align_second) || NIL_P (max_calls) - || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (interval, T_FIXNUM); - Check_Type (align_second, T_FIXNUM); - Check_Type (max_calls, T_FIXNUM); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_interval = FIX2INT (interval); - c_align_second = FIX2INT (align_second); - c_max_calls = FIX2INT (max_calls); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_timer (weechat_ruby_plugin, - ruby_current_script, - c_interval, - c_align_second, - c_max_calls, - &weechat_ruby_api_hook_timer_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_ruby_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_fd: hook a fd - */ - -static VALUE -weechat_ruby_api_hook_fd (VALUE class, VALUE fd, VALUE read, VALUE write, - VALUE exception, VALUE function, VALUE data) -{ - int c_fd, c_read, c_write, c_exception; - char *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - if (NIL_P (fd) || NIL_P (read) || NIL_P (write) || NIL_P (exception) - || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (fd, T_FIXNUM); - Check_Type (read, T_FIXNUM); - Check_Type (write, T_FIXNUM); - Check_Type (exception, T_FIXNUM); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_fd = FIX2INT (fd); - c_read = FIX2INT (read); - c_write = FIX2INT (write); - c_exception = FIX2INT (exception); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_fd (weechat_ruby_plugin, - ruby_current_script, - c_fd, - c_read, - c_write, - c_exception, - &weechat_ruby_api_hook_fd_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_process_cb: callback for process hooked - */ - -int -weechat_ruby_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = &return_code; - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssiss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_process: hook a process - */ - -static VALUE -weechat_ruby_api_hook_process (VALUE class, VALUE command, VALUE timeout, - VALUE function, VALUE data) -{ - char *c_command, *c_function, *c_data, *result; - int c_timeout; - VALUE return_value; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - if (NIL_P (command) || NIL_P (timeout) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (command, T_STRING); - Check_Type (timeout, T_FIXNUM); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_command = StringValuePtr (command); - c_timeout = FIX2INT (timeout); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_process (weechat_ruby_plugin, - ruby_current_script, - c_command, - c_timeout, - &weechat_ruby_api_hook_process_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_process_hashtable: hook a process with options in - * a hashtable - */ - -static VALUE -weechat_ruby_api_hook_process_hashtable (VALUE class, VALUE command, - VALUE options, VALUE timeout, - VALUE function, VALUE data) -{ - char *c_command, *c_function, *c_data, *result; - struct t_hashtable *c_options; - int c_timeout; - VALUE return_value; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - if (NIL_P (command) || NIL_P (options) || NIL_P (timeout) - || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (command, T_STRING); - Check_Type (options, T_HASH); - Check_Type (timeout, T_FIXNUM); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_command = StringValuePtr (command); - c_options = weechat_ruby_hash_to_hashtable (options, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - c_timeout = FIX2INT (timeout); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_ruby_plugin, - ruby_current_script, - c_command, - c_options, - c_timeout, - &weechat_ruby_api_hook_process_cb, - c_function, - c_data)); - - if (c_options) - weechat_hashtable_free (c_options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_ruby_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_connect: hook a connection - */ - -static VALUE -weechat_ruby_api_hook_connect (VALUE class, VALUE proxy, VALUE address, - VALUE port, VALUE sock, VALUE ipv6, - VALUE local_hostname, VALUE function, - VALUE data) -{ - char *c_proxy, *c_address, *c_local_hostname, *c_function, *c_data, *result; - int c_port, c_sock, c_ipv6; - VALUE return_value; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - if (NIL_P (proxy) || NIL_P (address) || NIL_P (port) || NIL_P (sock) - || NIL_P (ipv6) || NIL_P (local_hostname) || NIL_P (function) - || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (proxy, T_STRING); - Check_Type (address, T_STRING); - Check_Type (port, T_FIXNUM); - Check_Type (sock, T_FIXNUM); - Check_Type (ipv6, T_FIXNUM); - Check_Type (local_hostname, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_proxy = StringValuePtr (proxy); - c_address = StringValuePtr (address); - c_port = FIX2INT (port); - c_sock = FIX2INT (sock); - c_ipv6 = FIX2INT (ipv6); - c_local_hostname = StringValuePtr (local_hostname); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_connect (weechat_ruby_plugin, - ruby_current_script, - c_proxy, - c_address, - c_port, - c_sock, - c_ipv6, - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - c_local_hostname, - &weechat_ruby_api_hook_connect_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_print_cb: callback for print hooked - */ - -int -weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_print: hook a print - */ - -static VALUE -weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE tags, - VALUE message, VALUE strip_colors, VALUE function, - VALUE data) -{ - char *c_buffer, *c_tags, *c_message, *c_function, *c_data, *result; - int c_strip_colors; - VALUE return_value; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (tags) || NIL_P (message) - || NIL_P (strip_colors) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (tags, T_STRING); - Check_Type (message, T_STRING); - Check_Type (strip_colors, T_FIXNUM); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_tags = StringValuePtr (tags); - c_message = StringValuePtr (message); - c_strip_colors = FIX2INT (strip_colors); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_print (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer), - c_tags, - c_message, - c_strip_colors, - &weechat_ruby_api_hook_print_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_ruby_api_hook_signal_cb (void *data, const char *signal, const char *type_data, - void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_signal: hook a signal - */ - -static VALUE -weechat_ruby_api_hook_signal (VALUE class, VALUE signal, VALUE function, - VALUE data) -{ - char *c_signal, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - if (NIL_P (signal) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (signal, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_signal = StringValuePtr (signal); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_signal (weechat_ruby_plugin, - ruby_current_script, - c_signal, - &weechat_ruby_api_hook_signal_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_signal_send: send a signal - */ - -static VALUE -weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data, - VALUE signal_data) -{ - char *c_signal, *c_type_data, *c_signal_data; - int number; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - if (NIL_P (signal) || NIL_P (type_data) || NIL_P (signal_data)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (signal, T_STRING); - Check_Type (type_data, T_STRING); - - c_signal = StringValuePtr (signal); - c_type_data = StringValuePtr (type_data); - - if (strcmp (c_type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - Check_Type (signal_data, T_STRING); - c_signal_data = StringValuePtr (signal_data); - weechat_hook_signal_send (c_signal, c_type_data, c_signal_data); - API_RETURN_OK; - } - else if (strcmp (c_type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - Check_Type (signal_data, T_FIXNUM); - number = FIX2INT (signal_data); - weechat_hook_signal_send (c_signal, c_type_data, &number); - API_RETURN_OK; - } - else if (strcmp (c_type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - Check_Type (signal_data, T_STRING); - c_signal_data = StringValuePtr (signal_data); - weechat_hook_signal_send (c_signal, c_type_data, - API_STR2PTR(c_signal_data)); - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_ruby_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_ruby_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = hashtable; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssh", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_hsignal: hook a hsignal - */ - -static VALUE -weechat_ruby_api_hook_hsignal (VALUE class, VALUE signal, VALUE function, - VALUE data) -{ - char *c_signal, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - if (NIL_P (signal) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (signal, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_signal = StringValuePtr (signal); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_hsignal (weechat_ruby_plugin, - ruby_current_script, - c_signal, - &weechat_ruby_api_hook_hsignal_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_hsignal_send: send a hsignal - */ - -static VALUE -weechat_ruby_api_hook_hsignal_send (VALUE class, VALUE signal, VALUE hashtable) -{ - char *c_signal; - struct t_hashtable *c_hashtable; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - if (NIL_P (signal) || NIL_P (hashtable)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (signal, T_STRING); - Check_Type (hashtable, T_HASH); - - c_signal = StringValuePtr (signal); - c_hashtable = weechat_ruby_hash_to_hashtable (hashtable, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (c_signal, c_hashtable); - - if (c_hashtable) - weechat_hashtable_free (c_hashtable); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_ruby_api_hook_config_cb (void *data, const char *option, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_config: hook a config option - */ - -static VALUE -weechat_ruby_api_hook_config (VALUE class, VALUE option, VALUE function, - VALUE data) -{ - char *c_option, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - if (NIL_P (option) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (option, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_option = StringValuePtr (option); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_config (weechat_ruby_plugin, - ruby_current_script, - c_option, - &weechat_ruby_api_hook_config_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_ruby_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_hook_completion: hook a completion - */ - -static VALUE -weechat_ruby_api_hook_completion (VALUE class, VALUE completion, - VALUE description, VALUE function, - VALUE data) -{ - char *c_completion, *c_description, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (NIL_P (completion) || NIL_P (description) || NIL_P (function) - || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (completion, T_STRING); - Check_Type (description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_completion = StringValuePtr (completion); - c_description = StringValuePtr (description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_completion (weechat_ruby_plugin, - ruby_current_script, - c_completion, - c_description, - &weechat_ruby_api_hook_completion_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_completion_list_add: add a word to list for a completion - */ - -static VALUE -weechat_ruby_api_hook_completion_list_add (VALUE class, VALUE completion, - VALUE word, VALUE nick_completion, - VALUE where) -{ - char *c_completion, *c_word, *c_where; - int c_nick_completion; - - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion) - || NIL_P (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (completion, T_STRING); - Check_Type (word, T_STRING); - Check_Type (nick_completion, T_FIXNUM); - Check_Type (where, T_STRING); - - c_completion = StringValuePtr (completion); - c_word = StringValuePtr (word); - c_nick_completion = FIX2INT (nick_completion); - c_where = StringValuePtr (where); - - weechat_hook_completion_list_add (API_STR2PTR(c_completion), - c_word, - c_nick_completion, - c_where); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_ruby_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat_ruby_api_hook_modifier: hook a modifier - */ - -static VALUE -weechat_ruby_api_hook_modifier (VALUE class, VALUE modifier, VALUE function, - VALUE data) -{ - char *c_modifier, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - if (NIL_P (modifier) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (modifier, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_modifier = StringValuePtr (modifier); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_modifier (weechat_ruby_plugin, - ruby_current_script, - c_modifier, - &weechat_ruby_api_hook_modifier_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_modifier_exec: execute a modifier hook - */ - -static VALUE -weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier, - VALUE modifier_data, VALUE string) -{ - char *c_modifier, *c_modifier_data, *c_string, *result; - VALUE return_value; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - if (NIL_P (modifier) || NIL_P (modifier_data) || NIL_P (string)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (modifier, T_STRING); - Check_Type (modifier_data, T_STRING); - Check_Type (string, T_STRING); - - c_modifier = StringValuePtr (modifier); - c_modifier_data = StringValuePtr (modifier_data); - c_string = StringValuePtr (string); - - result = weechat_hook_modifier_exec (c_modifier, c_modifier_data, c_string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_ruby_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat_ruby_api_hook_info: hook an info - */ - -static VALUE -weechat_ruby_api_hook_info (VALUE class, VALUE info_name, VALUE description, - VALUE args_description, VALUE function, VALUE data) -{ - char *c_info_name, *c_description, *c_args_description, *c_function; - char *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - if (NIL_P (info_name) || NIL_P (description) || NIL_P (args_description) - || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (info_name, T_STRING); - Check_Type (description, T_STRING); - Check_Type (args_description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_info_name = StringValuePtr (info_name); - c_description = StringValuePtr (description); - c_args_description = StringValuePtr (args_description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_info (weechat_ruby_plugin, - ruby_current_script, - c_info_name, - c_description, - c_args_description, - &weechat_ruby_api_hook_info_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_ruby_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = hashtable; - - return (struct t_hashtable *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssh", func_argv); - } - - return NULL; -} - -/* - * weechat_ruby_api_hook_info_hashtable: hook an info_hashtable - */ - -static VALUE -weechat_ruby_api_hook_info_hashtable (VALUE class, VALUE info_name, - VALUE description, - VALUE args_description, - VALUE output_description, - VALUE function, VALUE data) -{ - char *c_info_name, *c_description, *c_args_description; - char *c_output_description, *c_function; - char *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - if (NIL_P (info_name) || NIL_P (description) || NIL_P (args_description) - || NIL_P (output_description) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (info_name, T_STRING); - Check_Type (description, T_STRING); - Check_Type (args_description, T_STRING); - Check_Type (output_description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_info_name = StringValuePtr (info_name); - c_description = StringValuePtr (description); - c_args_description = StringValuePtr (args_description); - c_output_description = StringValuePtr (output_description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_ruby_plugin, - ruby_current_script, - c_info_name, - c_description, - c_args_description, - c_output_description, - &weechat_ruby_api_hook_info_hashtable_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_ruby_api_hook_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat_ruby_api_hook_infolist: hook an infolist - */ - -static VALUE -weechat_ruby_api_hook_infolist (VALUE class, VALUE infolist_name, - VALUE description, VALUE pointer_description, - VALUE args_description, VALUE function, - VALUE data) -{ - char *c_infolist_name, *c_description, *c_pointer_description; - char *c_args_description, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - if (NIL_P (infolist_name) || NIL_P (description) - || NIL_P (pointer_description) || NIL_P (args_description) - || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist_name, T_STRING); - Check_Type (description, T_STRING); - Check_Type (pointer_description, T_STRING); - Check_Type (args_description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_infolist_name = StringValuePtr (infolist_name); - c_description = StringValuePtr (description); - c_pointer_description = StringValuePtr (pointer_description); - c_args_description = StringValuePtr (args_description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_infolist (weechat_ruby_plugin, - ruby_current_script, - c_infolist_name, - c_description, - c_pointer_description, - c_args_description, - &weechat_ruby_api_hook_infolist_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_ruby_api_hook_focus_cb (void *data, struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = info; - - return (struct t_hashtable *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sh", func_argv); - } - - return NULL; -} - -/* - * weechat_ruby_api_hook_focus: hook a focus - */ - -static VALUE -weechat_ruby_api_hook_focus (VALUE class, VALUE area, VALUE function, - VALUE data) -{ - char *c_area, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - if (NIL_P (area) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (area, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_area = StringValuePtr (area); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_hook_focus (weechat_ruby_plugin, - ruby_current_script, - c_area, - &weechat_ruby_api_hook_focus_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_unhook: unhook something - */ - -static VALUE -weechat_ruby_api_unhook (VALUE class, VALUE hook) -{ - char *c_hook; - - API_FUNC(1, "unhook", API_RETURN_ERROR); - if (NIL_P (hook)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (hook, T_STRING); - - c_hook = StringValuePtr (hook); - - script_api_unhook (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_hook)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_unhook_all: unhook all for script - */ - -static VALUE -weechat_ruby_api_unhook_all (VALUE class) -{ - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_ruby_plugin, ruby_current_script); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_ruby_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_buffer_close_cb: callback for closed buffer - */ - -int -weechat_ruby_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_buffer_new: create a new buffer - */ - -static VALUE -weechat_ruby_api_buffer_new (VALUE class, VALUE name, VALUE function_input, - VALUE data_input, VALUE function_close, - VALUE data_close) -{ - char *c_name, *c_function_input, *c_data_input, *c_function_close; - char *c_data_close, *result; - VALUE return_value; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - if (NIL_P (name) || NIL_P (function_input) || NIL_P (data_input) - || NIL_P (function_close) || NIL_P (data_close)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - Check_Type (function_input, T_STRING); - Check_Type (data_input, T_STRING); - Check_Type (function_close, T_STRING); - Check_Type (data_close, T_STRING); - - c_name = StringValuePtr (name); - c_function_input = StringValuePtr (function_input); - c_data_input = StringValuePtr (data_input); - c_function_close = StringValuePtr (function_close); - c_data_close = StringValuePtr (data_close); - - result = script_ptr2str (script_api_buffer_new (weechat_ruby_plugin, - ruby_current_script, - c_name, - &weechat_ruby_api_buffer_input_data_cb, - c_function_input, - c_data_input, - &weechat_ruby_api_buffer_close_cb, - c_function_close, - c_data_close)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_buffer_search: search a buffer - */ - -static VALUE -weechat_ruby_api_buffer_search (VALUE class, VALUE plugin, VALUE name) -{ - char *c_plugin, *c_name, *result; - VALUE return_value; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - if (NIL_P (plugin) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (plugin, T_STRING); - Check_Type (name, T_STRING); - - c_plugin = StringValuePtr (plugin); - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_buffer_search (c_plugin, c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_buffer_search_main: search main buffer (WeeChat core buffer) - */ - -static VALUE -weechat_ruby_api_buffer_search_main (VALUE class) -{ - char *result; - VALUE return_value; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_current_buffer: get current buffer - */ - -static VALUE -weechat_ruby_api_current_buffer (VALUE class) -{ - char *result; - VALUE return_value; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_buffer_clear: clear a buffer - */ - -static VALUE -weechat_ruby_api_buffer_clear (VALUE class, VALUE buffer) -{ - char *c_buffer; - - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - if (NIL_P (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - - c_buffer = StringValuePtr (buffer); - - weechat_buffer_clear (API_STR2PTR(c_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_close: close a buffer - */ - -static VALUE -weechat_ruby_api_buffer_close (VALUE class, VALUE buffer) -{ - char *c_buffer; - - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - if (NIL_P (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - - c_buffer = StringValuePtr (buffer); - - script_api_buffer_close (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_merge: merge a buffer to another buffer - */ - -static VALUE -weechat_ruby_api_buffer_merge (VALUE class, VALUE buffer, VALUE target_buffer) -{ - char *c_buffer, *c_target_buffer; - - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (target_buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (target_buffer, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_target_buffer = StringValuePtr (target_buffer); - - weechat_buffer_merge (API_STR2PTR(c_buffer), - API_STR2PTR(c_target_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_unmerge: unmerge a buffer from a group of merged - * buffers - */ - -static VALUE -weechat_ruby_api_buffer_unmerge (VALUE class, VALUE buffer, VALUE number) -{ - char *c_buffer; - int c_number; - - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (number)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (number, T_FIXNUM); - - c_buffer = StringValuePtr (buffer); - c_number = FIX2INT (number); - - weechat_buffer_unmerge (API_STR2PTR(c_buffer), c_number); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_get_integer: get a buffer property as integer - */ - -static VALUE -weechat_ruby_api_buffer_get_integer (VALUE class, VALUE buffer, VALUE property) -{ - char *c_buffer, *c_property; - int value; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - if (NIL_P (buffer) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (buffer, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_property = StringValuePtr (property); - - value = weechat_buffer_get_integer (API_STR2PTR(c_buffer), - c_property); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_buffer_get_string: get a buffer property as string - */ - -static VALUE -weechat_ruby_api_buffer_get_string (VALUE class, VALUE buffer, VALUE property) -{ - char *c_buffer, *c_property; - const char *result; - - API_FUNC(1, "buffer_get_string", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_property = StringValuePtr (property); - - result = weechat_buffer_get_string (API_STR2PTR(c_buffer), - c_property); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_buffer_get_pointer: get a buffer property as pointer - */ - -static VALUE -weechat_ruby_api_buffer_get_pointer (VALUE class, VALUE buffer, VALUE property) -{ - char *c_buffer, *c_property, *result; - VALUE return_value; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_property = StringValuePtr (property); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(c_buffer), - c_property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_buffer_set: set a buffer property - */ - -static VALUE -weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property, - VALUE value) -{ - char *c_buffer, *c_property, *c_value; - - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (property) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (property, T_STRING); - Check_Type (value, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_property = StringValuePtr (property); - c_value = StringValuePtr (value); - - weechat_buffer_set (API_STR2PTR(c_buffer), - c_property, - c_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_buffer_string_replace_local_var: replace local variables ($var) in a string, - * using value of local variables - */ - -static VALUE -weechat_ruby_api_buffer_string_replace_local_var (VALUE class, VALUE buffer, VALUE string) -{ - char *c_buffer, *c_string, *result; - VALUE return_value; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (string)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (string, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_string = StringValuePtr (string); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(c_buffer), c_string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_buffer_match_list: return 1 if buffer matches list of buffers - */ - -static VALUE -weechat_ruby_api_buffer_match_list (VALUE class, VALUE buffer, VALUE string) -{ - char *c_buffer, *c_string; - int value; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - if (NIL_P (buffer) || NIL_P (string)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (buffer, T_STRING); - Check_Type (string, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_string = StringValuePtr (string); - - value = weechat_buffer_match_list (API_STR2PTR(c_buffer), - c_string); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_current_window: get current window - */ - -static VALUE -weechat_ruby_api_current_window (VALUE class) -{ - char *result; - VALUE return_value; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_window_search_with_buffer: search a window with buffer - * pointer - */ - -static VALUE -weechat_ruby_api_window_search_with_buffer (VALUE class, VALUE buffer) -{ - char *c_buffer, *result; - VALUE return_value; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - if (NIL_P (buffer)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - - c_buffer = StringValuePtr (buffer); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(c_buffer))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_window_get_integer: get a window property as integer - */ - -static VALUE -weechat_ruby_api_window_get_integer (VALUE class, VALUE window, VALUE property) -{ - char *c_window, *c_property; - int value; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - if (NIL_P (window) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (window, T_STRING); - Check_Type (property, T_STRING); - - c_window = StringValuePtr (window); - c_property = StringValuePtr (property); - - value = weechat_window_get_integer (API_STR2PTR(c_window), - c_property); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_window_get_string: get a window property as string - */ - -static VALUE -weechat_ruby_api_window_get_string (VALUE class, VALUE window, VALUE property) -{ - char *c_window, *c_property; - const char *result; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - if (NIL_P (window) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (window, T_STRING); - Check_Type (property, T_STRING); - - c_window = StringValuePtr (window); - c_property = StringValuePtr (property); - - result = weechat_window_get_string (API_STR2PTR(c_window), - c_property); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_window_get_pointer: get a window property as pointer - */ - -static VALUE -weechat_ruby_api_window_get_pointer (VALUE class, VALUE window, VALUE property) -{ - char *c_window, *c_property, *result; - VALUE return_value; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - if (NIL_P (window) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (window, T_STRING); - Check_Type (property, T_STRING); - - c_window = StringValuePtr (window); - c_property = StringValuePtr (property); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(c_window), - c_property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_window_set_title: set window title - */ - -static VALUE -weechat_ruby_api_window_set_title (VALUE class, VALUE title) -{ - char *c_title; - - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - if (NIL_P (title)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (title, T_STRING); - - c_title = StringValuePtr (title); - - weechat_window_set_title (c_title); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_nicklist_add_group: add a group in nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_add_group (VALUE class, VALUE buffer, - VALUE parent_group, VALUE name, - VALUE color, VALUE visible) -{ - char *c_buffer, *c_parent_group, *c_name, *c_color, *result; - int c_visible; - VALUE return_value; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (parent_group) || NIL_P (name) || NIL_P (color) - || NIL_P (visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (parent_group, T_STRING); - Check_Type (name, T_STRING); - Check_Type (color, T_STRING); - Check_Type (visible, T_FIXNUM); - - c_buffer = StringValuePtr (buffer); - c_parent_group = StringValuePtr (parent_group); - c_name = StringValuePtr (name); - c_color = StringValuePtr (color); - c_visible = FIX2INT (visible); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(c_buffer), - API_STR2PTR(c_parent_group), - c_name, - c_color, - c_visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_search_group: search a group in nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_search_group (VALUE class, VALUE buffer, - VALUE from_group, VALUE name) -{ - char *c_buffer, *c_from_group, *c_name, *result; - VALUE return_value; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (from_group) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (from_group, T_STRING); - Check_Type (name, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_from_group = StringValuePtr (from_group); - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(c_buffer), - API_STR2PTR(c_from_group), - c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_add_nick: add a nick in nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_add_nick (VALUE class, VALUE buffer, VALUE group, - VALUE name, VALUE color, VALUE prefix, - VALUE prefix_color, VALUE visible) -{ - char *c_buffer, *c_group, *c_name, *c_color, *c_prefix, *c_prefix_color; - char *result; - int c_visible; - VALUE return_value; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (group) || NIL_P (name) || NIL_P (color) - || NIL_P (prefix) || NIL_P (prefix_color) || NIL_P (visible)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - Check_Type (name, T_STRING); - Check_Type (color, T_STRING); - Check_Type (prefix, T_STRING); - Check_Type (prefix_color, T_STRING); - Check_Type (visible, T_FIXNUM); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - c_name = StringValuePtr (name); - c_color = StringValuePtr (color); - c_prefix = StringValuePtr (prefix); - c_prefix_color = StringValuePtr (prefix_color); - c_visible = FIX2INT (visible); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(c_buffer), - API_STR2PTR(c_group), - c_name, - c_color, - c_prefix, - c_prefix_color, - c_visible)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_search_nick: search a nick in nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_search_nick (VALUE class, VALUE buffer, - VALUE from_group, VALUE name) -{ - char *c_buffer, *c_from_group, *c_name, *result; - VALUE return_value; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (from_group) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (from_group, T_STRING); - Check_Type (name, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_from_group = StringValuePtr (from_group); - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(c_buffer), - API_STR2PTR(c_from_group), - c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_remove_group: remove a group from nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_remove_group (VALUE class, VALUE buffer, VALUE group) -{ - char *c_buffer, *c_group; - - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (group)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - - weechat_nicklist_remove_group (API_STR2PTR(c_buffer), - API_STR2PTR(c_group)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_nicklist_remove_nick: remove a nick from nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_remove_nick (VALUE class, VALUE buffer, VALUE nick) -{ - char *c_buffer, *c_nick; - - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (nick)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (nick, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_nick = StringValuePtr (nick); - - weechat_nicklist_remove_nick (API_STR2PTR(c_buffer), - API_STR2PTR(c_nick)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_nicklist_remove_all: remove all groups/nicks from nicklist - */ - -static VALUE -weechat_ruby_api_nicklist_remove_all (VALUE class, VALUE buffer) -{ - char *c_buffer; - - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - if (NIL_P (buffer)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - - c_buffer = StringValuePtr (buffer); - - weechat_nicklist_remove_all (API_STR2PTR(c_buffer)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_nicklist_group_get_integer: get a group property as integer - */ - -static VALUE -weechat_ruby_api_nicklist_group_get_integer (VALUE class, VALUE buffer, - VALUE group, VALUE property) -{ - char *c_buffer, *c_group, *c_property; - int value; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - if (NIL_P (buffer) || NIL_P (group) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - c_property = StringValuePtr (property); - - value = weechat_nicklist_group_get_integer (API_STR2PTR(c_buffer), - API_STR2PTR(c_group), - c_property); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_nicklist_group_get_string: get a group property as string - */ - -static VALUE -weechat_ruby_api_nicklist_group_get_string (VALUE class, VALUE buffer, - VALUE group, VALUE property) -{ - char *c_buffer, *c_group, *c_property; - const char *result; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (group) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - c_property = StringValuePtr (property); - - result = weechat_nicklist_group_get_string (API_STR2PTR(c_buffer), - API_STR2PTR(c_group), - c_property); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_nicklist_group_get_pointer: get a group property as pointer - */ - -static VALUE -weechat_ruby_api_nicklist_group_get_pointer (VALUE class, VALUE buffer, - VALUE group, VALUE property) -{ - char *c_buffer, *c_group, *c_property, *result; - VALUE return_value; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (group) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - c_property = StringValuePtr (property); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(c_buffer), - API_STR2PTR(c_group), - c_property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_group_set: set a group property - */ - -static VALUE -weechat_ruby_api_nicklist_group_set (VALUE class, VALUE buffer, VALUE group, - VALUE property, VALUE value) -{ - char *c_buffer, *c_group, *c_property, *c_value; - - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (group) || NIL_P (property) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (group, T_STRING); - Check_Type (property, T_STRING); - Check_Type (value, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_group = StringValuePtr (group); - c_property = StringValuePtr (property); - c_value = StringValuePtr (value); - - weechat_nicklist_group_set (API_STR2PTR(c_buffer), - API_STR2PTR(c_group), - c_property, - c_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_nicklist_nick_get_integer: get a nick property as integer - */ - -static VALUE -weechat_ruby_api_nicklist_nick_get_integer (VALUE class, VALUE buffer, - VALUE nick, VALUE property) -{ - char *c_buffer, *c_nick, *c_property; - int value; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - if (NIL_P (buffer) || NIL_P (nick) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (buffer, T_STRING); - Check_Type (nick, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_nick = StringValuePtr (nick); - c_property = StringValuePtr (property); - - value = weechat_nicklist_nick_get_integer (API_STR2PTR(c_buffer), - API_STR2PTR(c_nick), - c_property); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_nicklist_nick_get_string: get a nick property as string - */ - -static VALUE -weechat_ruby_api_nicklist_nick_get_string (VALUE class, VALUE buffer, - VALUE nick, VALUE property) -{ - char *c_buffer, *c_nick, *c_property; - const char *result; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (nick) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (nick, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_nick = StringValuePtr (nick); - c_property = StringValuePtr (property); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(c_buffer), - API_STR2PTR(c_nick), - c_property); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_nicklist_nick_get_pointer: get a nick property as pointer - */ - -static VALUE -weechat_ruby_api_nicklist_nick_get_pointer (VALUE class, VALUE buffer, - VALUE nick, VALUE property) -{ - char *c_buffer, *c_nick, *c_property, *result; - VALUE return_value; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - if (NIL_P (buffer) || NIL_P (nick) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (buffer, T_STRING); - Check_Type (nick, T_STRING); - Check_Type (property, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_nick = StringValuePtr (nick); - c_property = StringValuePtr (property); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(c_buffer), - API_STR2PTR(c_nick), - c_property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_nicklist_nick_set: set a nick property - */ - -static VALUE -weechat_ruby_api_nicklist_nick_set (VALUE class, VALUE buffer, VALUE nick, - VALUE property, VALUE value) -{ - char *c_buffer, *c_nick, *c_property, *c_value; - - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (nick) || NIL_P (property) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (nick, T_STRING); - Check_Type (property, T_STRING); - Check_Type (value, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_nick = StringValuePtr (nick); - c_property = StringValuePtr (property); - c_value = StringValuePtr (value); - - weechat_nicklist_nick_set (API_STR2PTR(c_buffer), - API_STR2PTR(c_nick), - c_property, - c_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_bar_item_search: search a bar item - */ - -static VALUE -weechat_ruby_api_bar_item_search (VALUE class, VALUE name) -{ - char *c_name, *result; - VALUE return_value; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - if (NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_bar_item_search (c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_ruby_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat_ruby_api_bar_item_new: add a new bar item - */ - -static VALUE -weechat_ruby_api_bar_item_new (VALUE class, VALUE name, VALUE function, - VALUE data) -{ - char *c_name, *c_function, *c_data, *result; - VALUE return_value; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - if (NIL_P (name) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_name = StringValuePtr (name); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = script_ptr2str (script_api_bar_item_new (weechat_ruby_plugin, - ruby_current_script, - c_name, - &weechat_ruby_api_bar_item_build_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_bar_item_update: update a bar item on screen - */ - -static VALUE -weechat_ruby_api_bar_item_update (VALUE class, VALUE name) -{ - char *c_name; - - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - if (NIL_P (name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (name, T_STRING); - - c_name = StringValuePtr (name); - - weechat_bar_item_update (c_name); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_bar_item_remove: remove a bar item - */ - -static VALUE -weechat_ruby_api_bar_item_remove (VALUE class, VALUE item) -{ - char *c_item; - - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - if (NIL_P (item)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (item, T_STRING); - - c_item = StringValuePtr (item); - - script_api_bar_item_remove (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_item)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_bar_search: search a bar - */ - -static VALUE -weechat_ruby_api_bar_search (VALUE class, VALUE name) -{ - char *c_name, *result; - VALUE return_value; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - if (NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_bar_search (c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_bar_new: add a new bar - */ - -static VALUE -weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE hidden, - VALUE priority, VALUE type, VALUE conditions, - VALUE position, VALUE filling_top_bottom, - VALUE filling_left_right, VALUE size, - VALUE size_max, VALUE color_fg, VALUE color_delim, - VALUE color_bg, VALUE separator, VALUE items) -{ - char *c_name, *c_hidden, *c_priority, *c_type, *c_conditions, *c_position; - char *c_filling_top_bottom, *c_filling_left_right, *c_size, *c_size_max; - char *c_color_fg, *c_color_delim, *c_color_bg, *c_separator, *c_items; - char *result; - VALUE return_value; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - if (NIL_P (name) || NIL_P (hidden) || NIL_P (priority) || NIL_P (type) - || NIL_P (conditions) || NIL_P (position) || NIL_P (filling_top_bottom) - || NIL_P (filling_left_right) || NIL_P (size) || NIL_P (size_max) - || NIL_P (color_fg) || NIL_P (color_delim) || NIL_P (color_bg) - || NIL_P (separator) || NIL_P (items)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - Check_Type (hidden, T_STRING); - Check_Type (priority, T_STRING); - Check_Type (type, T_STRING); - Check_Type (conditions, T_STRING); - Check_Type (position, T_STRING); - Check_Type (filling_top_bottom, T_STRING); - Check_Type (filling_left_right, T_STRING); - Check_Type (size, T_STRING); - Check_Type (size_max, T_STRING); - Check_Type (color_fg, T_STRING); - Check_Type (color_delim, T_STRING); - Check_Type (color_bg, T_STRING); - Check_Type (separator, T_STRING); - Check_Type (items, T_STRING); - - c_name = StringValuePtr (name); - c_hidden = StringValuePtr (hidden); - c_priority = StringValuePtr (priority); - c_type = StringValuePtr (type); - c_conditions = StringValuePtr (conditions); - c_position = StringValuePtr (position); - c_filling_top_bottom = StringValuePtr (filling_top_bottom); - c_filling_left_right = StringValuePtr (filling_left_right); - c_size = StringValuePtr (size); - c_size_max = StringValuePtr (size_max); - c_color_fg = StringValuePtr (color_fg); - c_color_delim = StringValuePtr (color_delim); - c_color_bg = StringValuePtr (color_bg); - c_separator = StringValuePtr (separator); - c_items = StringValuePtr (items); - - result = script_ptr2str (weechat_bar_new (c_name, - c_hidden, - c_priority, - c_type, - c_conditions, - c_position, - c_filling_top_bottom, - c_filling_left_right, - c_size, - c_size_max, - c_color_fg, - c_color_delim, - c_color_bg, - c_separator, - c_items)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_bar_set: set a bar property - */ - -static VALUE -weechat_ruby_api_bar_set (VALUE class, VALUE bar, VALUE property, VALUE value) -{ - char *c_bar, *c_property, *c_value; - - API_FUNC(1, "bar_set", API_RETURN_ERROR); - if (NIL_P (bar) || NIL_P (property) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (bar, T_STRING); - Check_Type (property, T_STRING); - Check_Type (value, T_STRING); - - c_bar = StringValuePtr (bar); - c_property = StringValuePtr (property); - c_value = StringValuePtr (value); - - weechat_bar_set (API_STR2PTR(c_bar), - c_property, - c_value); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_bar_update: update a bar on screen - */ - -static VALUE -weechat_ruby_api_bar_update (VALUE class, VALUE name) -{ - char *c_name; - - API_FUNC(1, "bar_update", API_RETURN_ERROR); - if (NIL_P (name)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (name, T_STRING); - - c_name = StringValuePtr (name); - - weechat_bar_update (c_name); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_bar_remove: remove a bar - */ - -static VALUE -weechat_ruby_api_bar_remove (VALUE class, VALUE bar) -{ - char *c_bar; - - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - if (NIL_P (bar)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (bar, T_STRING); - - c_bar = StringValuePtr (bar); - - weechat_bar_remove (API_STR2PTR(c_bar)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_command: send command to server - */ - -static VALUE -weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command) -{ - char *c_buffer, *c_command; - - API_FUNC(1, "command", API_RETURN_ERROR); - if (NIL_P (buffer) || NIL_P (command)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (buffer, T_STRING); - Check_Type (command, T_STRING); - - c_buffer = StringValuePtr (buffer); - c_command = StringValuePtr (command); - - script_api_command (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_buffer), - c_command); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_info_get: get info (as string) - */ - -static VALUE -weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments) -{ - char *c_info_name, *c_arguments; - const char *result; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - if (NIL_P (info_name) || NIL_P (arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (info_name, T_STRING); - Check_Type (arguments, T_STRING); - - c_info_name = StringValuePtr (info_name); - c_arguments = StringValuePtr (arguments); - - result = weechat_info_get (c_info_name, c_arguments); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_info_get_hashtable: get info (as hashtable) - */ - -static VALUE -weechat_ruby_api_info_get_hashtable (VALUE class, VALUE info_name, - VALUE hash) -{ - char *c_info_name; - struct t_hashtable *c_hashtable, *result_hashtable; - VALUE result_hash; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - if (NIL_P (info_name) || NIL_P (hash)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (info_name, T_STRING); - Check_Type (hash, T_HASH); - - c_info_name = StringValuePtr (info_name); - c_hashtable = weechat_ruby_hash_to_hashtable (hash, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (c_info_name, c_hashtable); - result_hash = weechat_ruby_hashtable_to_hash (result_hashtable); - - if (c_hashtable) - weechat_hashtable_free (c_hashtable); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - return result_hash; -} - -/* - * weechat_ruby_api_infolist_new: create new infolist - */ - -static VALUE -weechat_ruby_api_infolist_new (VALUE class) -{ - char *result; - VALUE return_value; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_new_item: create new item in infolist - */ - -static VALUE -weechat_ruby_api_infolist_new_item (VALUE class, VALUE infolist) -{ - char *c_infolist, *result; - VALUE return_value; - - API_FUNC(1, "infolist_new_item", API_RETURN_EMPTY); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(c_infolist))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_new_var_integer: create new integer variable in - * infolist - */ - -static VALUE -weechat_ruby_api_infolist_new_var_integer (VALUE class, VALUE infolist, - VALUE name, VALUE value) -{ - char *c_infolist, *c_name, *result; - int c_value; - VALUE return_value; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (name) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (name, T_STRING); - Check_Type (value, T_FIXNUM); - - c_infolist = StringValuePtr (infolist); - c_name = StringValuePtr (name); - c_value = FIX2INT (value); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(c_infolist), - c_name, - c_value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_new_var_string: create new string variable in - * infolist - */ - -static VALUE -weechat_ruby_api_infolist_new_var_string (VALUE class, VALUE infolist, - VALUE name, VALUE value) -{ - char *c_infolist, *c_name, *c_value, *result; - VALUE return_value; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (name) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (name, T_STRING); - Check_Type (value, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_name = StringValuePtr (name); - c_value = StringValuePtr (value); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(c_infolist), - c_name, - c_value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_new_var_pointer: create new pointer variable in - * infolist - */ - -static VALUE -weechat_ruby_api_infolist_new_var_pointer (VALUE class, VALUE infolist, - VALUE name, VALUE value) -{ - char *c_infolist, *c_name, *c_value, *result; - VALUE return_value; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (name) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (name, T_STRING); - Check_Type (value, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_name = StringValuePtr (name); - c_value = StringValuePtr (value); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(c_infolist), - c_name, - API_STR2PTR(c_value))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_new_var_time: create new time variable in infolist - */ - -static VALUE -weechat_ruby_api_infolist_new_var_time (VALUE class, VALUE infolist, - VALUE name, VALUE value) -{ - char *c_infolist, *c_name, *result; - int c_value; - VALUE return_value; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (name) || NIL_P (value)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (name, T_STRING); - Check_Type (value, T_FIXNUM); - - c_infolist = StringValuePtr (infolist); - c_name = StringValuePtr (name); - c_value = FIX2INT (value); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(c_infolist), - c_name, - c_value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_get: get list with infos - */ - -static VALUE -weechat_ruby_api_infolist_get (VALUE class, VALUE name, VALUE pointer, - VALUE arguments) -{ - char *c_name, *c_pointer, *c_arguments, *result; - VALUE return_value; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - if (NIL_P (name) || NIL_P (pointer) || NIL_P (arguments)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (arguments, T_STRING); - - c_name = StringValuePtr (name); - c_pointer = StringValuePtr (pointer); - c_arguments = StringValuePtr (arguments); - - result = script_ptr2str (weechat_infolist_get (c_name, - API_STR2PTR(c_pointer), - c_arguments)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_next: move item pointer to next item in infolist - */ - -static VALUE -weechat_ruby_api_infolist_next (VALUE class, VALUE infolist) -{ - char *c_infolist; - int value; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - value = weechat_infolist_next (API_STR2PTR(c_infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_infolist_prev: move item pointer to previous item in infolist - */ - -static VALUE -weechat_ruby_api_infolist_prev (VALUE class, VALUE infolist) -{ - char *c_infolist; - int value; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - value = weechat_infolist_prev (API_STR2PTR(c_infolist)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_infolist_reset_item_cursor: reset pointer to current item - * in infolist - */ - -static VALUE -weechat_ruby_api_infolist_reset_item_cursor (VALUE class, VALUE infolist) -{ - char *c_infolist; - - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - weechat_infolist_reset_item_cursor (API_STR2PTR(c_infolist)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_infolist_fields: get list of fields for current item of infolist - */ - -static VALUE -weechat_ruby_api_infolist_fields (VALUE class, VALUE infolist) -{ - char *c_infolist; - const char *result; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - result = weechat_infolist_fields (API_STR2PTR(c_infolist)); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_infolist_integer: get integer value of a variable in infolist - */ - -static VALUE -weechat_ruby_api_infolist_integer (VALUE class, VALUE infolist, VALUE variable) -{ - char *c_infolist, *c_variable; - int value; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - if (NIL_P (infolist) || NIL_P (variable)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (infolist, T_STRING); - Check_Type (variable, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_variable = StringValuePtr (variable); - - value = weechat_infolist_integer (API_STR2PTR(c_infolist), c_variable); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_infolist_string: get string value of a variable in infolist - */ - -static VALUE -weechat_ruby_api_infolist_string (VALUE class, VALUE infolist, VALUE variable) -{ - char *c_infolist, *c_variable; - const char *result; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (variable, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_variable = StringValuePtr (variable); - - result = weechat_infolist_string (API_STR2PTR(c_infolist), c_variable); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_infolist_pointer: get pointer value of a variable in infolist - */ - -static VALUE -weechat_ruby_api_infolist_pointer (VALUE class, VALUE infolist, VALUE variable) -{ - char *c_infolist, *c_variable, *result; - VALUE return_value; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (variable, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_variable = StringValuePtr (variable); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(c_infolist), c_variable)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_time: get time value of a variable in infolist - */ - -static VALUE -weechat_ruby_api_infolist_time (VALUE class, VALUE infolist, VALUE variable) -{ - char *c_infolist, *c_variable, timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - VALUE return_value; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - if (NIL_P (infolist) || NIL_P (variable)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (infolist, T_STRING); - Check_Type (variable, T_STRING); - - c_infolist = StringValuePtr (infolist); - c_variable = StringValuePtr (variable); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(c_infolist), c_variable); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_infolist_free: free infolist - */ - -static VALUE -weechat_ruby_api_infolist_free (VALUE class, VALUE infolist) -{ - char *c_infolist; - - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - if (NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (infolist, T_STRING); - - c_infolist = StringValuePtr (infolist); - - weechat_infolist_free (API_STR2PTR(c_infolist)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_hdata_get: get hdata - */ - -static VALUE -weechat_ruby_api_hdata_get (VALUE class, VALUE name) -{ - char *c_name, *result; - VALUE return_value; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - if (NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (name, T_STRING); - - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_hdata_get (c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hdata_get_var_offset: get offset of variable in hdata - */ - -static VALUE -weechat_ruby_api_hdata_get_var_offset (VALUE class, VALUE hdata, VALUE name) -{ - char *c_hdata, *c_name; - int value; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - if (NIL_P (hdata) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (hdata, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_name = StringValuePtr (name); - - value = weechat_hdata_get_var_offset (API_STR2PTR(c_hdata), c_name); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_hdata_get_var_type_string: get type of variable as string - * in hdata - */ - -static VALUE -weechat_ruby_api_hdata_get_var_type_string (VALUE class, VALUE hdata, - VALUE name) -{ - char *c_hdata, *c_name; - const char *result; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_name = StringValuePtr (name); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(c_hdata), c_name); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_hdata_get_var_array_size: get array size for variable in hdata - */ - -static VALUE -weechat_ruby_api_hdata_get_var_array_size (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - int value; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - value = weechat_hdata_get_var_array_size (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_hdata_get_var_array_size_string: get array size for variable - * in hdata (as string) - */ - -static VALUE -weechat_ruby_api_hdata_get_var_array_size_string (VALUE class, VALUE hdata, - VALUE pointer, VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - const char *result; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_hdata_get_var_hdata: get hdata for variable in hdata - */ - -static VALUE -weechat_ruby_api_hdata_get_var_hdata (VALUE class, VALUE hdata, VALUE name) -{ - char *c_hdata, *c_name; - const char *result; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_name = StringValuePtr (name); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(c_hdata), c_name); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_hdata_get_list: get list pointer in hdata - */ - -static VALUE -weechat_ruby_api_hdata_get_list (VALUE class, VALUE hdata, VALUE name) -{ - char *c_hdata, *c_name, *result; - VALUE return_value; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(c_hdata), - c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hdata_check_pointer: check pointer with hdata/list - */ - -static VALUE -weechat_ruby_api_hdata_check_pointer (VALUE class, VALUE hdata, VALUE list, - VALUE pointer) -{ - char *c_hdata, *c_list, *c_pointer; - int value; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - if (NIL_P (hdata) || NIL_P (list) || NIL_P (pointer)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (hdata, T_STRING); - Check_Type (list, T_STRING); - Check_Type (pointer, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_list = StringValuePtr (list); - c_pointer = StringValuePtr (pointer); - - value = weechat_hdata_check_pointer (API_STR2PTR(c_hdata), - API_STR2PTR(c_list), - API_STR2PTR(c_pointer)); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_hdata_move: move pointer to another element in list - */ - -static VALUE -weechat_ruby_api_hdata_move (VALUE class, VALUE hdata, VALUE pointer, - VALUE count) -{ - char *c_hdata, *c_pointer, *result; - int c_count; - VALUE return_value; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (count)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (count, T_FIXNUM); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_count = FIX2INT (count); - - result = weechat_hdata_move (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_count); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hdata_char: get char value of a variable in structure using - * hdata - */ - -static VALUE -weechat_ruby_api_hdata_char (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - int value; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - value = (int)weechat_hdata_char (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_hdata_integer: get integer value of a variable in structure - * using hdata - */ - -static VALUE -weechat_ruby_api_hdata_integer (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - int value; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - value = weechat_hdata_integer (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_INT(value); -} - -/* - * weechat_ruby_api_hdata_long: get long value of a variable in structure using - * hdata - */ - -static VALUE -weechat_ruby_api_hdata_long (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - long value; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - value = weechat_hdata_long (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_LONG(value); -} - -/* - * weechat_ruby_api_hdata_string: get string value of a variable in structure - * using hdata - */ - -static VALUE -weechat_ruby_api_hdata_string (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - const char *result; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - result = weechat_hdata_string (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_hdata_pointer: get pointer value of a variable in structure - * using hdata - */ - -static VALUE -weechat_ruby_api_hdata_pointer (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name, *result; - VALUE return_value; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hdata_time: get time value of a variable in structure using - * hdata - */ - -static VALUE -weechat_ruby_api_hdata_time (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name, timebuffer[64], *result; - time_t time; - struct tm *date_tmp; - VALUE return_value; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_hdata_hashtable: get hashtable value of a variable in - * structure using hdata - */ - -static VALUE -weechat_ruby_api_hdata_hashtable (VALUE class, VALUE hdata, VALUE pointer, - VALUE name) -{ - char *c_hdata, *c_pointer, *c_name; - VALUE result_hash; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (name)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (pointer, T_STRING); - Check_Type (name, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_pointer = StringValuePtr (pointer); - c_name = StringValuePtr (name); - - result_hash = weechat_ruby_hashtable_to_hash ( - weechat_hdata_hashtable (API_STR2PTR(c_hdata), - API_STR2PTR(c_pointer), - c_name)); - - return result_hash; -} - -/* - * weechat_ruby_api_hdata_get_string: get hdata property as string - */ - -static VALUE -weechat_ruby_api_hdata_get_string (VALUE class, VALUE hdata, VALUE property) -{ - char *c_hdata, *c_property; - const char *result; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (hdata, T_STRING); - Check_Type (property, T_STRING); - - c_hdata = StringValuePtr (hdata); - c_property = StringValuePtr (property); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(c_hdata), - c_property); - - API_RETURN_STRING(result); -} - -/* - * weechat_ruby_api_upgrade_new: create an upgrade file - */ - -static VALUE -weechat_ruby_api_upgrade_new (VALUE class, VALUE filename, VALUE write) -{ - char *c_filename, *result; - int c_write; - VALUE return_value; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - if (NIL_P (filename) || NIL_P (write)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (filename, T_STRING); - Check_Type (write, T_FIXNUM); - - c_filename = StringValuePtr (filename); - c_write = FIX2INT (write); - - result = script_ptr2str (weechat_upgrade_new (c_filename, - c_write)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_ruby_api_upgrade_write_object: write object in upgrade file - */ - -static VALUE -weechat_ruby_api_upgrade_write_object (VALUE class, VALUE upgrade_file, - VALUE object_id, VALUE infolist) -{ - char *c_upgrade_file, *c_infolist; - int c_object_id, rc; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - if (NIL_P (upgrade_file) || NIL_P (object_id) || NIL_P (infolist)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (upgrade_file, T_STRING); - Check_Type (object_id, T_FIXNUM); - Check_Type (infolist, T_STRING); - - c_upgrade_file = StringValuePtr (upgrade_file); - c_object_id = FIX2INT (object_id); - c_infolist = StringValuePtr (infolist); - - rc = weechat_upgrade_write_object (API_STR2PTR(c_upgrade_file), - c_object_id, - API_STR2PTR(c_infolist)); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_upgrade_read_cb: callback for reading object in upgrade file - */ - -int -weechat_ruby_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_ruby_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_ruby_api_upgrade_read: read upgrade file - */ - -static VALUE -weechat_ruby_api_upgrade_read (VALUE class, VALUE upgrade_file, - VALUE function, VALUE data) -{ - char *c_upgrade_file, *c_function, *c_data; - int rc; - - API_FUNC(1, "upgrade_read", API_RETURN_INT(0)); - if (NIL_P (upgrade_file) || NIL_P (function) || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_INT(0)); - - Check_Type (upgrade_file, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_upgrade_file = StringValuePtr (upgrade_file); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - rc = script_api_upgrade_read (weechat_ruby_plugin, - ruby_current_script, - API_STR2PTR(c_upgrade_file), - &weechat_ruby_api_upgrade_read_cb, - c_function, - c_data); - - API_RETURN_INT(rc); -} - -/* - * weechat_ruby_api_upgrade_close: close upgrade file - */ - -static VALUE -weechat_ruby_api_upgrade_close (VALUE class, VALUE upgrade_file) -{ - char *c_upgrade_file; - - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - if (NIL_P (upgrade_file)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (upgrade_file, T_STRING); - - c_upgrade_file = StringValuePtr (upgrade_file); - - weechat_upgrade_close (API_STR2PTR(c_upgrade_file)); - - API_RETURN_OK; -} - -/* - * weechat_ruby_api_init: init Ruby API: add variables and functions - */ - -void -weechat_ruby_api_init (VALUE ruby_mWeechat) -{ - rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK", INT2NUM(WEECHAT_RC_OK)); - rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_EAT", INT2NUM(WEECHAT_RC_OK_EAT)); - rb_define_const(ruby_mWeechat, "WEECHAT_RC_ERROR", INT2NUM(WEECHAT_RC_ERROR)); - - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_READ_OK", INT2NUM(WEECHAT_CONFIG_READ_OK)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_READ_MEMORY_ERROR", INT2NUM(WEECHAT_CONFIG_READ_MEMORY_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_READ_FILE_NOT_FOUND", INT2NUM(WEECHAT_CONFIG_READ_FILE_NOT_FOUND)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_WRITE_OK", INT2NUM(WEECHAT_CONFIG_WRITE_OK)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_WRITE_ERROR", INT2NUM(WEECHAT_CONFIG_WRITE_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_WRITE_MEMORY_ERROR", INT2NUM(WEECHAT_CONFIG_WRITE_MEMORY_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", INT2NUM(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", INT2NUM(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_SET_ERROR", INT2NUM(WEECHAT_CONFIG_OPTION_SET_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", INT2NUM(WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", INT2NUM(WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", INT2NUM(WEECHAT_CONFIG_OPTION_UNSET_OK_RESET)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", INT2NUM(WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED)); - rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_OPTION_UNSET_ERROR", INT2NUM(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_SORT", rb_str_new2(WEECHAT_LIST_POS_SORT)); - rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_BEGINNING", rb_str_new2(WEECHAT_LIST_POS_BEGINNING)); - rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_END", rb_str_new2(WEECHAT_LIST_POS_END)); - - rb_define_const(ruby_mWeechat, "WEECHAT_HOTLIST_LOW", rb_str_new2(WEECHAT_HOTLIST_LOW)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOTLIST_MESSAGE", rb_str_new2(WEECHAT_HOTLIST_MESSAGE)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOTLIST_PRIVATE", rb_str_new2(WEECHAT_HOTLIST_PRIVATE)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOTLIST_HIGHLIGHT", rb_str_new2(WEECHAT_HOTLIST_HIGHLIGHT)); - - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_PROCESS_RUNNING", INT2NUM(WEECHAT_HOOK_PROCESS_RUNNING)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_PROCESS_ERROR", INT2NUM(WEECHAT_HOOK_PROCESS_ERROR)); - - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_OK", INT2NUM(WEECHAT_HOOK_CONNECT_OK)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", INT2NUM(WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", INT2NUM(WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", INT2NUM(WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_PROXY_ERROR", INT2NUM(WEECHAT_HOOK_CONNECT_PROXY_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", INT2NUM(WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", INT2NUM(WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", INT2NUM(WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_MEMORY_ERROR", INT2NUM(WEECHAT_HOOK_CONNECT_MEMORY_ERROR)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_CONNECT_TIMEOUT", INT2NUM(WEECHAT_HOOK_CONNECT_TIMEOUT)); - - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_SIGNAL_STRING", rb_str_new2(WEECHAT_HOOK_SIGNAL_STRING)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_SIGNAL_INT", rb_str_new2(WEECHAT_HOOK_SIGNAL_INT)); - rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_SIGNAL_POINTER", rb_str_new2(WEECHAT_HOOK_SIGNAL_POINTER)); - - API_DEF_FUNC(register, 7); - API_DEF_FUNC(plugin_get_name, 1); - API_DEF_FUNC(charset_set, 1); - API_DEF_FUNC(iconv_to_internal, 2); - API_DEF_FUNC(iconv_from_internal, 2); - API_DEF_FUNC(gettext, 1); - API_DEF_FUNC(ngettext, 3); - API_DEF_FUNC(string_match, 3); - API_DEF_FUNC(string_has_highlight, 2); - API_DEF_FUNC(string_has_highlight_regex, 2); - API_DEF_FUNC(string_mask_to_regex, 1); - API_DEF_FUNC(string_remove_color, 2); - API_DEF_FUNC(string_is_command_char, 1); - API_DEF_FUNC(string_input_for_buffer, 1); - API_DEF_FUNC(mkdir_home, 2); - API_DEF_FUNC(mkdir, 2); - API_DEF_FUNC(mkdir_parents, 2); - API_DEF_FUNC(list_new, 0); - API_DEF_FUNC(list_add, 4); - API_DEF_FUNC(list_search, 2); - API_DEF_FUNC(list_search_pos, 2); - API_DEF_FUNC(list_casesearch, 2); - API_DEF_FUNC(list_casesearch_pos, 2); - API_DEF_FUNC(list_get, 2); - API_DEF_FUNC(list_set, 2); - API_DEF_FUNC(list_next, 1); - API_DEF_FUNC(list_prev, 1); - API_DEF_FUNC(list_string, 1); - API_DEF_FUNC(list_size, 1); - API_DEF_FUNC(list_remove, 2); - API_DEF_FUNC(list_remove_all, 1); - API_DEF_FUNC(list_free, 1); - API_DEF_FUNC(config_new, 3); - API_DEF_FUNC(config_new_section, 14); - API_DEF_FUNC(config_search_section, 2); - API_DEF_FUNC(config_new_option, 17); - API_DEF_FUNC(config_search_option, 3); - API_DEF_FUNC(config_string_to_boolean, 1); - API_DEF_FUNC(config_option_reset, 2); - API_DEF_FUNC(config_option_set, 3); - API_DEF_FUNC(config_option_set_null, 2); - API_DEF_FUNC(config_option_unset, 1); - API_DEF_FUNC(config_option_rename, 2); - API_DEF_FUNC(config_option_is_null, 1); - API_DEF_FUNC(config_option_default_is_null, 1); - API_DEF_FUNC(config_boolean, 1); - API_DEF_FUNC(config_boolean_default, 1); - API_DEF_FUNC(config_integer, 1); - API_DEF_FUNC(config_integer_default, 1); - API_DEF_FUNC(config_string, 1); - API_DEF_FUNC(config_string_default, 1); - API_DEF_FUNC(config_color, 1); - API_DEF_FUNC(config_color_default, 1); - API_DEF_FUNC(config_write_option, 2); - API_DEF_FUNC(config_write_line, 3); - API_DEF_FUNC(config_write, 1); - API_DEF_FUNC(config_read, 1); - API_DEF_FUNC(config_reload, 1); - API_DEF_FUNC(config_option_free, 1); - API_DEF_FUNC(config_section_free_options, 1); - API_DEF_FUNC(config_section_free, 1); - API_DEF_FUNC(config_free, 1); - API_DEF_FUNC(config_get, 1); - API_DEF_FUNC(config_get_plugin, 1); - API_DEF_FUNC(config_is_set_plugin, 1); - API_DEF_FUNC(config_set_plugin, 2); - API_DEF_FUNC(config_set_desc_plugin, 2); - API_DEF_FUNC(config_unset_plugin, 1); - API_DEF_FUNC(key_bind, 2); - API_DEF_FUNC(key_unbind, 2); - API_DEF_FUNC(prefix, 1); - API_DEF_FUNC(color, 1); - API_DEF_FUNC(print, 2); - API_DEF_FUNC(print_date_tags, 4); - API_DEF_FUNC(print_y, 3); - API_DEF_FUNC(log_print, 1); - API_DEF_FUNC(hook_command, 7); - API_DEF_FUNC(hook_command_run, 3); - API_DEF_FUNC(hook_timer, 5); - API_DEF_FUNC(hook_fd, 6); - API_DEF_FUNC(hook_process, 4); - API_DEF_FUNC(hook_process_hashtable, 5); - API_DEF_FUNC(hook_connect, 8); - API_DEF_FUNC(hook_print, 6); - API_DEF_FUNC(hook_signal, 3); - API_DEF_FUNC(hook_signal_send, 3); - API_DEF_FUNC(hook_hsignal, 3); - API_DEF_FUNC(hook_hsignal_send, 2); - API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_list_add, 4); - API_DEF_FUNC(hook_modifier, 3); - API_DEF_FUNC(hook_modifier_exec, 3); - API_DEF_FUNC(hook_info, 5); - API_DEF_FUNC(hook_info_hashtable, 6); - API_DEF_FUNC(hook_infolist, 6); - API_DEF_FUNC(hook_focus, 3); - API_DEF_FUNC(unhook, 1); - API_DEF_FUNC(unhook_all, 0); - API_DEF_FUNC(buffer_new, 5); - API_DEF_FUNC(buffer_search, 2); - API_DEF_FUNC(buffer_search_main, 0); - API_DEF_FUNC(current_buffer, 0); - API_DEF_FUNC(buffer_clear, 1); - API_DEF_FUNC(buffer_close, 1); - API_DEF_FUNC(buffer_merge, 2); - API_DEF_FUNC(buffer_unmerge, 2); - API_DEF_FUNC(buffer_get_integer, 2); - API_DEF_FUNC(buffer_get_string, 2); - API_DEF_FUNC(buffer_get_pointer, 2); - API_DEF_FUNC(buffer_set, 3); - API_DEF_FUNC(buffer_string_replace_local_var, 2); - API_DEF_FUNC(buffer_match_list, 2); - API_DEF_FUNC(current_window, 0); - API_DEF_FUNC(window_search_with_buffer, 1); - API_DEF_FUNC(window_get_integer, 2); - API_DEF_FUNC(window_get_string, 2); - API_DEF_FUNC(window_get_pointer, 2); - API_DEF_FUNC(window_set_title, 1); - API_DEF_FUNC(nicklist_add_group, 5); - API_DEF_FUNC(nicklist_search_group, 3); - API_DEF_FUNC(nicklist_add_nick, 7); - API_DEF_FUNC(nicklist_search_nick, 3); - API_DEF_FUNC(nicklist_remove_group, 2); - API_DEF_FUNC(nicklist_remove_nick, 2); - API_DEF_FUNC(nicklist_remove_all, 1); - API_DEF_FUNC(nicklist_group_get_integer, 3); - API_DEF_FUNC(nicklist_group_get_string, 3); - API_DEF_FUNC(nicklist_group_get_pointer, 3); - API_DEF_FUNC(nicklist_group_set, 4); - API_DEF_FUNC(nicklist_nick_get_integer, 3); - API_DEF_FUNC(nicklist_nick_get_string, 3); - API_DEF_FUNC(nicklist_nick_get_pointer, 3); - API_DEF_FUNC(nicklist_nick_set, 4); - API_DEF_FUNC(bar_item_search, 1); - API_DEF_FUNC(bar_item_new, 3); - API_DEF_FUNC(bar_item_update, 1); - API_DEF_FUNC(bar_item_remove, 1); - API_DEF_FUNC(bar_search, 1); - API_DEF_FUNC(bar_new, 15); - API_DEF_FUNC(bar_set, 3); - API_DEF_FUNC(bar_update, 1); - API_DEF_FUNC(bar_remove, 1); - API_DEF_FUNC(command, 2); - API_DEF_FUNC(info_get, 2); - API_DEF_FUNC(info_get_hashtable, 2); - API_DEF_FUNC(infolist_new, 0); - API_DEF_FUNC(infolist_new_item, 1); - API_DEF_FUNC(infolist_new_var_integer, 3); - API_DEF_FUNC(infolist_new_var_string, 3); - API_DEF_FUNC(infolist_new_var_pointer, 3); - API_DEF_FUNC(infolist_new_var_time, 3); - API_DEF_FUNC(infolist_get, 3); - API_DEF_FUNC(infolist_next, 1); - API_DEF_FUNC(infolist_prev, 1); - API_DEF_FUNC(infolist_reset_item_cursor, 1); - API_DEF_FUNC(infolist_fields, 1); - API_DEF_FUNC(infolist_integer, 2); - API_DEF_FUNC(infolist_string, 2); - API_DEF_FUNC(infolist_pointer, 2); - API_DEF_FUNC(infolist_time, 2); - API_DEF_FUNC(infolist_free, 1); - API_DEF_FUNC(hdata_get, 1); - API_DEF_FUNC(hdata_get_var_offset, 2); - API_DEF_FUNC(hdata_get_var_type_string, 2); - API_DEF_FUNC(hdata_get_var_array_size, 3); - API_DEF_FUNC(hdata_get_var_array_size_string, 3); - API_DEF_FUNC(hdata_get_var_hdata, 2); - API_DEF_FUNC(hdata_get_list, 2); - API_DEF_FUNC(hdata_check_pointer, 3); - API_DEF_FUNC(hdata_move, 3); - API_DEF_FUNC(hdata_char, 3); - API_DEF_FUNC(hdata_integer, 3); - API_DEF_FUNC(hdata_long, 3); - API_DEF_FUNC(hdata_string, 3); - API_DEF_FUNC(hdata_pointer, 3); - API_DEF_FUNC(hdata_time, 3); - API_DEF_FUNC(hdata_hashtable, 3); - API_DEF_FUNC(hdata_get_string, 2); - API_DEF_FUNC(upgrade_new, 2); - API_DEF_FUNC(upgrade_write_object, 3); - API_DEF_FUNC(upgrade_read, 3); - API_DEF_FUNC(upgrade_close, 1); -} diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.h b/src/plugins/scripts/ruby/weechat-ruby-api.h deleted file mode 100644 index 708bf518f..000000000 --- a/src/plugins/scripts/ruby/weechat-ruby-api.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_RUBY_API_H -#define __WEECHAT_RUBY_API_H 1 - -extern int weechat_ruby_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_ruby_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); -extern void weechat_ruby_api_init (VALUE ruby_mWeechat); - -#endif /* __WEECHAT_RUBY_API_H */ diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c deleted file mode 100644 index 01709ac74..000000000 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ /dev/null @@ -1,1112 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-ruby.c: ruby plugin for WeeChat - */ - -#undef _ - -#include <ruby.h> -#if defined(RUBY_VERSION) && RUBY_VERSION >=19 -#include <ruby/encoding.h> -#endif - -#include <stdarg.h> -#include <sys/types.h> -#include <sys/stat.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-ruby.h" -#include "weechat-ruby-api.h" - -#ifndef StringValuePtr -#define StringValuePtr(s) STR2CSTR(s) -#endif -#ifndef RARRAY_LEN -#define RARRAY_LEN(s) RARRAY(s)->len -#endif -#ifndef RARRAY_PTR -#define RARRAY_PTR(s) RARRAY(s)->ptr -#endif -#ifndef RSTRING_LEN -#define RSTRING_LEN(s) RSTRING(s)->len -#endif -#ifndef RSTRING_PTR -#define RSTRING_PTR(s) RSTRING(s)->ptr -#endif - - -WEECHAT_PLUGIN_NAME(RUBY_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of ruby scripts")); -WEECHAT_PLUGIN_AUTHOR("Sebastien Helleu <flashcode@flashtux.org>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_ruby_plugin = NULL; - -int ruby_quiet = 0; -int ruby_hide_errors = 0; -struct t_plugin_script *ruby_scripts = NULL; -struct t_plugin_script *last_ruby_script = NULL; -struct t_plugin_script *ruby_current_script = NULL; -struct t_plugin_script *ruby_registered_script = NULL; -const char *ruby_current_script_filename = NULL; - -/* - * string used to execute action "install": - * when signal "ruby_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *ruby_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "ruby_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *ruby_action_remove_list = NULL; - -VALUE ruby_mWeechat, ruby_mWeechatOutputs; - -#define MOD_NAME_PREFIX "WeechatRubyModule" -int ruby_num = 0; - -char ruby_buffer_output[128]; - -typedef struct protect_call_arg { - VALUE recv; - ID mid; - int argc; - VALUE *argv; -} protect_call_arg_t; - - -/* - * weechat_ruby_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_ruby_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - VALUE *hash; - - /* make C compiler happy */ - (void) hashtable; - - hash = (VALUE *)data; - - rb_hash_aset (hash[0], rb_str_new2 (key), rb_str_new2 (value)); -} - -/* - * weechat_ruby_hashtable_to_hash: get ruby hash with a WeeChat hashtable - */ - -VALUE -weechat_ruby_hashtable_to_hash (struct t_hashtable *hashtable) -{ - VALUE hash; - - hash = rb_hash_new (); - if (NIL_P (hash)) - return Qnil; - - weechat_hashtable_map_string (hashtable, - &weechat_ruby_hashtable_map_cb, - &hash); - - return hash; -} - -int -weechat_ruby_hash_foreach_cb (VALUE key, VALUE value, void *arg) -{ - struct t_hashtable *hashtable; - - hashtable = (struct t_hashtable *)arg; - if ((TYPE(key) == T_STRING) && (TYPE(value) == T_STRING)) - { - weechat_hashtable_set (hashtable, StringValuePtr(key), - StringValuePtr(value)); - } - return 0; -} - -/* - * weechat_ruby_hash_to_hashtable: get WeeChat hashtable with ruby hashtable - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after use - * with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_ruby_hash_to_hashtable (VALUE hash, int hashtable_size) -{ - struct t_hashtable *hashtable; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - rb_hash_foreach (hash, &weechat_ruby_hash_foreach_cb, - (unsigned long)hashtable); - - return hashtable; -} - -/* - * protect_funcall0 : used to protect a function call - */ - -static VALUE -protect_funcall0 (VALUE arg) -{ - return rb_funcall2 (((protect_call_arg_t *)arg)->recv, - ((protect_call_arg_t *)arg)->mid, - ((protect_call_arg_t *)arg)->argc, - ((protect_call_arg_t *)arg)->argv); -} - -/* - * rb_protect_funcall: function call in protect mode - */ - -VALUE -rb_protect_funcall (VALUE recv, ID mid, int *state, int argc, VALUE *argv) -{ - struct protect_call_arg arg; - - arg.recv = recv; - arg.mid = mid; - arg.argc = argc; - arg.argv = argv; - return rb_protect (protect_funcall0, (VALUE) &arg, state); -} - -/* - * weechat_ruby_print_exception: display ruby exception - */ - -int -weechat_ruby_print_exception (VALUE err) -{ - VALUE backtrace, tmp1, tmp2, tmp3; - int i; - int ruby_error; - char* line; - char* cline; - char* err_msg; - char* err_class; - - backtrace = rb_protect_funcall (err, rb_intern("backtrace"), - &ruby_error, 0, NULL); - - tmp1 = rb_protect_funcall(err, rb_intern("message"), &ruby_error, 0, NULL); - err_msg = StringValueCStr(tmp1); - - tmp2 = rb_protect_funcall(rb_protect_funcall(err, rb_intern("class"), - &ruby_error, 0, NULL), - rb_intern("name"), &ruby_error, 0, NULL); - err_class = StringValuePtr(tmp2); - - if (strcmp (err_class, "SyntaxError") == 0) - { - tmp3 = rb_inspect(err); - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - StringValuePtr(tmp3)); - } - else - { - for (i = 0; i < RARRAY_LEN(backtrace); i++) - { - line = StringValuePtr(RARRAY_PTR(backtrace)[i]); - cline = NULL; - if (i == 0) - { - cline = (char *)calloc (strlen (line) + 2 + strlen (err_msg) + - 3 + strlen (err_class) + 1, - sizeof (char)); - if (cline) - { - strcat (cline, line); - strcat (cline, ": "); - strcat (cline, err_msg); - strcat (cline, " ("); - strcat (cline, err_class); - strcat (cline, ")"); - } - } - else - { - cline = (char *)calloc(strlen (line) + strlen (" from ") + 1, - sizeof (char)); - if (cline) - { - strcat (cline, " from "); - strcat (cline, line); - } - } - if (cline) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: error: %s"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - cline); - } - - if (cline) - free (cline); - } - } - - return 0; -} - -/* - * weechat_ruby_exec: execute a ruby function - */ - -void * -weechat_ruby_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv) -{ - VALUE rc, err; - int ruby_error, i, argc, *ret_i; - VALUE argv2[16]; - void *ret_value; - struct t_plugin_script *old_ruby_current_script; - - old_ruby_current_script = ruby_current_script; - ruby_current_script = script; - - argc = 0; - if (format && format[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - argv2[i] = rb_str_new2 ((char *)argv[i]); - break; - case 'i': /* integer */ - argv2[i] = INT2FIX (*((int *)argv[i])); - break; - case 'h': /* hash */ - argv2[i] = weechat_ruby_hashtable_to_hash (argv[i]); - break; - } - } - } - - if (argc > 0) - { - rc = rb_protect_funcall ((VALUE) script->interpreter, - rb_intern(function), - &ruby_error, argc, argv2); - } - else - { - rc = rb_protect_funcall ((VALUE) script->interpreter, - rb_intern(function), - &ruby_error, 0, NULL); - } - - if (ruby_error) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to run function \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, function); - - err = rb_gv_get("$!"); - weechat_ruby_print_exception(err); - - return NULL; - } - - if ((TYPE(rc) == T_STRING) && (ret_type == WEECHAT_SCRIPT_EXEC_STRING)) - { - if (StringValuePtr (rc)) - ret_value = strdup (StringValuePtr (rc)); - else - ret_value = NULL; - } - else if ((TYPE(rc) == T_FIXNUM) && (ret_type == WEECHAT_SCRIPT_EXEC_INT)) - { - ret_i = malloc (sizeof (*ret_i)); - if (ret_i) - *ret_i = NUM2INT(rc); - ret_value = ret_i; - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_value = weechat_ruby_hash_to_hashtable (rc, - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" must return a " - "valid value"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, function); - ruby_current_script = old_ruby_current_script; - return WEECHAT_RC_OK; - } - - if (ret_value == NULL) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: not enough memory in function " - "\"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, function); - ruby_current_script = old_ruby_current_script; - return NULL; - } - - ruby_current_script = old_ruby_current_script; - - return ret_value; -} - -/* - * weechat_ruby_output: redirection for stdout and stderr - */ - -static VALUE -weechat_ruby_output (VALUE self, VALUE str) -{ - if (ruby_hide_errors) - return Qnil; - - char *msg, *p, *m; - - /* make C compiler happy */ - (void) self; - - msg = strdup(StringValuePtr(str)); - - m = msg; - while ((p = strchr (m, '\n')) != NULL) - { - *p = '\0'; - if (strlen (m) + strlen (ruby_buffer_output) > 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: stdout/stderr: %s%s"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - ruby_buffer_output, m); - } - *p = '\n'; - ruby_buffer_output[0] = '\0'; - m = ++p; - } - - if (strlen(m) + strlen(ruby_buffer_output) > sizeof(ruby_buffer_output)) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: stdout/stderr: %s%s"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - ruby_buffer_output, m); - ruby_buffer_output[0] = '\0'; - } - else - strcat (ruby_buffer_output, m); - - if (msg) - free (msg); - - return Qnil; -} - -/* - * weechat_ruby_output_flush: just for compatibility - */ - -static VALUE -weechat_ruby_output_flush (VALUE self) -{ - /* make C compiler happy */ - (void) self; - - return Qnil; -} - -/* - * weechat_ruby_load: load a Ruby script - */ - -int -weechat_ruby_load (const char *filename) -{ - char modname[64]; - VALUE curModule, ruby_retcode, err, argv[1]; - int ruby_error; - struct stat buf; - - if (stat (filename, &buf) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not found"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); - return 0; - } - - if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - RUBY_PLUGIN_NAME, filename); - } - - ruby_current_script = NULL; - ruby_registered_script = NULL; - - snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); - ruby_num++; - - curModule = rb_define_module(modname); - - ruby_current_script_filename = filename; - - argv[0] = rb_str_new2 (filename); - ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"), - &ruby_error, 1, argv); - - if (ruby_retcode == Qnil) - { - err = rb_gv_get("$!"); - weechat_ruby_print_exception(err); - return 0; - } - - if (NUM2INT(ruby_retcode) != 0) - { - switch (NUM2INT(ruby_retcode)) - { - case 1: - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to read file " - "\"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - filename); - break; - case 2: - weechat_printf (NULL, - weechat_gettext ("%s%s: error while loading " - "file \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - filename); - break; - case 3: - weechat_printf (NULL, - weechat_gettext ("%s%s: function " - "\"weechat_init\" is missing " - "in file \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, - filename); - break; - } - - if (NUM2INT(ruby_retcode) == 1 || NUM2INT(ruby_retcode) == 2) - { - weechat_ruby_print_exception(rb_iv_get(curModule, "@load_eval_file_error")); - } - - return 0; - } - - (void) rb_protect_funcall (curModule, rb_intern("weechat_init"), - &ruby_error, 0, NULL); - - if (ruby_error) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to eval function " - "\"weechat_init\" in file \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); - - err = rb_gv_get("$!"); - weechat_ruby_print_exception(err); - - if (ruby_current_script != NULL) - { - script_remove (weechat_ruby_plugin, - &ruby_scripts, &last_ruby_script, - ruby_current_script); - } - - return 0; - } - - if (!ruby_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); - return 0; - } - ruby_current_script = ruby_registered_script; - - ruby_current_script->interpreter = (VALUE *) curModule; - rb_gc_register_address (ruby_current_script->interpreter); - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_ruby_plugin, - ruby_scripts, - ruby_current_script, - &weechat_ruby_api_buffer_input_data_cb, - &weechat_ruby_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_ruby_load_cb: callback for weechat_script_auto_load() function - */ - -void -weechat_ruby_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_ruby_load (filename); -} - -/* - * weechat_ruby_unload: unload a Ruby script - */ - -void -weechat_ruby_unload (struct t_plugin_script *script) -{ - int *rc; - void *interpreter; - - if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - RUBY_PLUGIN_NAME, script->name); - } - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *)weechat_ruby_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, - 0, NULL); - if (rc) - free (rc); - } - - interpreter = script->interpreter; - - if (ruby_current_script == script) - ruby_current_script = (ruby_current_script->prev_script) ? - ruby_current_script->prev_script : ruby_current_script->next_script; - - script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, - script); - - if (interpreter) - rb_gc_unregister_address (interpreter); -} - -/* - * weechat_ruby_unload_name: unload a Ruby script by name - */ - -void -weechat_ruby_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name); - if (ptr_script) - { - weechat_ruby_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - RUBY_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, name); - } -} - -/* - * weechat_ruby_reload_name: reload a Ruby script by name - */ - -void -weechat_ruby_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_ruby_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - RUBY_PLUGIN_NAME, name); - weechat_ruby_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, name); - } -} - -/* - * weechat_ruby_unload_all: unload all Ruby scripts - */ - -void -weechat_ruby_unload_all () -{ - while (ruby_scripts) - { - weechat_ruby_unload (ruby_scripts); - } -} - -/* - * weechat_ruby_command_cb: callback for "/ruby" command - */ - -int -weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_ruby_plugin, ruby_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_ruby_plugin, ruby_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_ruby_plugin, ruby_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_ruby_plugin, &weechat_ruby_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_ruby_unload_all (); - script_auto_load (weechat_ruby_plugin, &weechat_ruby_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_ruby_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_ruby_plugin, ruby_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_ruby_plugin, ruby_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Ruby script */ - path_script = script_search_path (weechat_ruby_plugin, - argv_eol[2]); - weechat_ruby_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Ruby script */ - weechat_ruby_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Ruby script */ - weechat_ruby_unload_name (argv_eol[2]); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), RUBY_PLUGIN_NAME, "ruby"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_ruby_completion_cb: callback for script completion - */ - -int -weechat_ruby_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_ruby_plugin, completion, ruby_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_ruby_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_ruby_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "ruby_script") == 0) - { - return script_infolist_list_scripts (weechat_ruby_plugin, - ruby_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_ruby_signal_debug_dump_cb: dump Ruby plugin data in WeeChat log file - */ - -int -weechat_ruby_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, RUBY_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_ruby_plugin, ruby_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_ruby_signal_buffer_closed_cb: callback called when a buffer is closed - */ - -int -weechat_ruby_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (ruby_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_ruby_timer_action_cb: timer for executing actions - */ - -int -weechat_ruby_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &ruby_action_install_list) - { - script_action_install (weechat_ruby_plugin, - ruby_scripts, - &weechat_ruby_unload, - &weechat_ruby_load, - &ruby_action_install_list); - } - else if (data == &ruby_action_remove_list) - { - script_action_remove (weechat_ruby_plugin, - ruby_scripts, - &weechat_ruby_unload, - &ruby_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_ruby_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_ruby_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "ruby_script_install") == 0) - { - script_action_add (&ruby_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_ruby_timer_action_cb, - &ruby_action_install_list); - } - else if (strcmp (signal, "ruby_script_remove") == 0) - { - script_action_add (&ruby_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_ruby_timer_action_cb, - &ruby_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_init: initialize Ruby plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; - int ruby_error; - char *weechat_ruby_code = - { - "$stdout = WeechatOutputs\n" - "$stderr = WeechatOutputs\n" - "begin" - " if RUBY_VERSION.split('.')[1] == '9'\n" - " require 'enc/encdb.so'\n" - " require 'enc/trans/transdb.so'\n" - "\n" - " require 'thread'\n" - " class ::Mutex\n" - " def synchronize(*args)\n" - " yield\n" - " end\n" - " end\n" - " require 'rubygems'\n" - " else\n" - " require 'rubygems'\n" - " end\n" - "rescue LoadError\n" - "end\n" - "\n" - "class Module\n" - "\n" - " def load_eval_file (file)\n" - " lines = ''\n" - " begin\n" - " lines = File.read(file)\n" - " rescue => e\n" - " return 1\n" - " end\n" - "\n" - " begin\n" - " module_eval(lines)\n" - " rescue Exception => e\n" - " @load_eval_file_error = e\n" - " return 2\n" - " end\n" - "\n" - " has_init = false\n" - "\n" - " instance_methods.each do |meth|\n" - " if meth.to_s == 'weechat_init'\n" - " has_init = true\n" - " end\n" - " module_eval('module_function :' + meth.to_s)\n" - " end\n" - "\n" - " unless has_init\n" - " return 3\n" - " end\n" - "\n" - " return 0\n" - " end\n" - "end\n" - }; - - weechat_ruby_plugin = plugin; - - ruby_error = 0; - - /* init stdout/stderr buffer */ - ruby_buffer_output[0] = '\0'; - -#if defined(RUBY_VERSION) && RUBY_VERSION >= 19 - RUBY_INIT_STACK; -#endif - - ruby_hide_errors = 1; - ruby_init (); - ruby_init_loadpath (); - ruby_script ("__weechat_plugin__"); - - ruby_mWeechat = rb_define_module("Weechat"); - weechat_ruby_api_init (ruby_mWeechat); - - /* redirect stdin and stdout */ - ruby_mWeechatOutputs = rb_define_module("WeechatOutputs"); - rb_define_singleton_method(ruby_mWeechatOutputs, "write", - weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "puts", - weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "p", - weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "flush", - weechat_ruby_output_flush, 0); - ruby_hide_errors = 0; - - rb_eval_string_protect(weechat_ruby_code, &ruby_error); - if (ruby_error) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to eval WeeChat ruby " - "internal code"), - weechat_prefix ("error"), RUBY_PLUGIN_NAME); - VALUE err = rb_gv_get("$!"); - weechat_ruby_print_exception(err); - return WEECHAT_RC_ERROR; - } - - init.callback_command = &weechat_ruby_command_cb; - init.callback_completion = &weechat_ruby_completion_cb; - init.callback_infolist = &weechat_ruby_infolist_cb; - init.callback_signal_debug_dump = &weechat_ruby_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_ruby_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_ruby_signal_script_action_cb; - init.callback_load_file = &weechat_ruby_load_cb; - - ruby_quiet = 1; - script_init (weechat_ruby_plugin, argc, argv, &init); - ruby_quiet = 0; - - script_display_short_list (weechat_ruby_plugin, - ruby_scripts); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: shutdown Ruby interface - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - ruby_quiet = 1; - script_end (plugin, &ruby_scripts, &weechat_ruby_unload_all); - ruby_quiet = 0; - - /* - * Do not cleanup Ruby because this causes a crash when plugin is reloaded - * again. This causes a memory leak, but I don't know better solution to - * this problem :( - */ - /*ruby_cleanup (0);*/ - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/ruby/weechat-ruby.h b/src/plugins/scripts/ruby/weechat-ruby.h deleted file mode 100644 index cf3e7a1b2..000000000 --- a/src/plugins/scripts/ruby/weechat-ruby.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * Copyright (C) 2005-2007 Emmanuel Bouthenot <kolter@openics.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_RUBY_H -#define __WEECHAT_RUBY_H 1 - -#define weechat_plugin weechat_ruby_plugin -#define RUBY_PLUGIN_NAME "ruby" - -#define RUBY_CURRENT_SCRIPT_NAME ((ruby_current_script) ? ruby_current_script->name : "-") - -extern struct t_weechat_plugin *weechat_ruby_plugin; - -extern int ruby_quiet; -extern struct t_plugin_script *ruby_scripts; -extern struct t_plugin_script *last_ruby_script; -extern struct t_plugin_script *ruby_current_script; -extern struct t_plugin_script *ruby_registered_script; -extern const char *ruby_current_script_filename; - -extern VALUE weechat_ruby_hashtable_to_hash (struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_ruby_hash_to_hashtable (VALUE dict, - int hashtable_size); -void *weechat_ruby_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv); - -#endif /* __WEECHAT_RUBY_H */ diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c deleted file mode 100644 index 4431dd086..000000000 --- a/src/plugins/scripts/script-api.c +++ /dev/null @@ -1,1479 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * script-api.c: script API functions, used by script plugins (perl/python/..) - */ - -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> -#include <stdio.h> - -#include "../weechat-plugin.h" -#include "script.h" -#include "script-api.h" -#include "script-callback.h" - - -/* - * script_api_charset_set: set charset for script - */ - -void -script_api_charset_set (struct t_plugin_script *script, - const char *charset) -{ - if (script->charset) - free (script->charset); - - script->charset = (charset) ? strdup (charset) : NULL; -} - -/* - * script_api_config_new: create a new configuration file - * return new configuration file, NULL if error - */ - -struct t_config_file * -script_api_config_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - int (*callback_reload)(void *data, - struct t_config_file *config_file), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_config_file *new_config_file; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_config_file = weechat_config_new (name, callback_reload, - (function && function[0]) ? script_cb : NULL); - if (new_config_file) - script_cb->config_file = new_config_file; - else - script_callback_remove (script, script_cb); - - return new_config_file; -} - -/* - * script_api_config_new_section: create a new section in configuration file - * return new section, NULL if error - */ - -struct t_config_section * -script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file, - const char *name, - int user_can_add_options, - int user_can_delete_options, - int (*callback_read)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value), - const char *function_read, - const char *data_read, - int (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), - const char *function_write, - const char *data_write, - int (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), - const char *function_write_default, - const char *data_write_default, - int (*callback_create_option)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value), - const char *function_create_option, - const char *data_create_option, - int (*callback_delete_option)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option), - const char *function_delete_option, - const char *data_delete_option) -{ - struct t_script_callback *script_cb_read, *script_cb_write; - struct t_script_callback *script_cb_write_default, *script_cb_create_option; - struct t_script_callback *script_cb_delete_option; - struct t_config_section *new_section; - - script_cb_read = script_callback_add (script, function_read, data_read); - script_cb_write = script_callback_add (script, function_write, data_write); - script_cb_write_default = script_callback_add (script, function_write_default, data_write_default); - script_cb_create_option = script_callback_add (script, function_create_option, data_create_option); - script_cb_delete_option = script_callback_add (script, function_delete_option, data_delete_option); - if (!script_cb_read || !script_cb_write || !script_cb_write_default - || !script_cb_create_option || !script_cb_delete_option) - { - if (script_cb_read) - script_callback_remove (script, script_cb_read); - if (script_cb_write) - script_callback_remove (script, script_cb_write); - if (script_cb_write_default) - script_callback_remove (script, script_cb_write_default); - if (script_cb_create_option) - script_callback_remove (script, script_cb_create_option); - if (script_cb_delete_option) - script_callback_remove (script, script_cb_delete_option); - return NULL; - } - - new_section = weechat_config_new_section (config_file, - name, - user_can_add_options, - user_can_delete_options, - (function_read && function_read[0]) ? callback_read : NULL, - (function_read && function_read[0]) ? script_cb_read : NULL, - (function_write && function_write[0]) ? callback_write : NULL, - (function_write && function_write[0]) ? script_cb_write : NULL, - (function_write_default && function_write_default[0]) ? callback_write_default : NULL, - (function_write_default && function_write_default[0]) ? script_cb_write_default : NULL, - (function_create_option && function_create_option[0]) ? callback_create_option : NULL, - (function_create_option && function_create_option[0]) ? script_cb_create_option : NULL, - (function_delete_option && function_delete_option[0]) ? callback_delete_option : NULL, - (function_delete_option && function_delete_option[0]) ? script_cb_delete_option : NULL); - if (new_section) - { - script_cb_read->config_file = config_file; - script_cb_read->config_section = new_section; - script_cb_write->config_file = config_file; - script_cb_write->config_section = new_section; - script_cb_write_default->config_file = config_file; - script_cb_write_default->config_section = new_section; - script_cb_create_option->config_file = config_file; - script_cb_create_option->config_section = new_section; - script_cb_delete_option->config_file = config_file; - script_cb_delete_option->config_section = new_section; - } - else - { - script_callback_remove (script, script_cb_read); - script_callback_remove (script, script_cb_write); - script_callback_remove (script, script_cb_write_default); - script_callback_remove (script, script_cb_create_option); - script_callback_remove (script, script_cb_delete_option); - } - - return new_section; -} - -/* - * script_api_config_new_option: create a new option in section - * return new option, NULL if error - */ - -struct t_config_option * -script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file, - struct t_config_section *section, - const char *name, const char *type, - const char *description, const char *string_values, - int min, int max, - const char *default_value, - const char *value, - int null_value_allowed, - int (*callback_check_value)(void *data, - struct t_config_option *option, - const char *value), - const char *function_check_value, - const char *data_check_value, - void (*callback_change)(void *data, - struct t_config_option *option), - const char *function_change, - const char *data_change, - void (*callback_delete)(void *data, - struct t_config_option *option), - const char *function_delete, - const char *data_delete) -{ - struct t_script_callback *script_cb_check_value, *script_cb_change; - struct t_script_callback *script_cb_delete; - struct t_config_option *new_option; - - script_cb_check_value = script_callback_add (script, function_check_value, data_check_value); - script_cb_change = script_callback_add (script, function_change, data_change); - script_cb_delete = script_callback_add (script, function_delete, data_delete); - if (!script_cb_check_value || !script_cb_change || !script_cb_delete) - { - if (script_cb_check_value) - script_callback_remove (script, script_cb_check_value); - if (script_cb_change) - script_callback_remove (script, script_cb_change); - if (script_cb_delete) - script_callback_remove (script, script_cb_delete); - return NULL; - } - - new_option = weechat_config_new_option (config_file, section, name, type, - description, string_values, min, - max, default_value, value, - null_value_allowed, - (function_check_value && function_check_value[0]) ? callback_check_value : NULL, - (function_check_value && function_check_value[0]) ? script_cb_check_value : NULL, - (function_change && function_change[0]) ? callback_change : NULL, - (function_change && function_change[0]) ? script_cb_change : NULL, - (function_delete && function_delete[0]) ? callback_delete : NULL, - (function_delete && function_delete[0]) ? script_cb_delete : NULL); - if (new_option) - { - script_cb_check_value->config_file = config_file; - script_cb_check_value->config_section = section; - script_cb_check_value->config_option = new_option; - script_cb_change->config_file = config_file; - script_cb_change->config_section = section; - script_cb_change->config_option = new_option; - script_cb_delete->config_file = config_file; - script_cb_delete->config_section = section; - script_cb_delete->config_option = new_option; - } - else - { - script_callback_remove (script, script_cb_check_value); - script_callback_remove (script, script_cb_change); - script_callback_remove (script, script_cb_delete); - } - - return new_option; -} - -/* - * script_api_config_option_free: free an option in configuration file - */ - -void -script_api_config_option_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_option *option) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !option) - return; - - weechat_config_option_free (option); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->config_option == option) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_config_section_free_options: free all options of a section in - * configuration file - */ - -void -script_api_config_section_free_options (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_section *section) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !section) - return; - - weechat_config_section_free_options (section); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if ((ptr_script_cb->config_section == section) - && ptr_script_cb->config_option) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_config_section_free: free a section in configuration file - */ - -void -script_api_config_section_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_section *section) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !section) - return; - - weechat_config_section_free (section); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->config_section == section) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_config_free: free configuration file - */ - -void -script_api_config_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !config_file) - return; - - weechat_config_free (config_file); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->config_file == config_file) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_printf: print a message - */ - -void -script_api_printf (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, const char *format, ...) -{ - char *buf2; - - weechat_va_format (format); - if (!vbuffer) - return; - - buf2 = (script && script->charset && script->charset[0]) ? - weechat_iconv_to_internal (script->charset, vbuffer) : NULL; - weechat_printf (buffer, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); - - free (vbuffer); -} - -/* - * script_api_printf_date_tags: print a message with optional date and tags - */ - -void -script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - time_t date, const char *tags, - const char *format, ...) -{ - char *buf2; - - weechat_va_format (format); - if (!vbuffer) - return; - - buf2 = (script->charset && script->charset[0]) ? - weechat_iconv_to_internal (script->charset, vbuffer) : NULL; - weechat_printf_date_tags (buffer, date, tags, - "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); - - free (vbuffer); -} - -/* - * script_api_printf_y: print a message on a buffer with free content - */ - -void -script_api_printf_y (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, int y, - const char *format, ...) -{ - char *buf2; - - weechat_va_format (format); - if (!vbuffer) - return; - - buf2 = (script->charset && script->charset[0]) ? - weechat_iconv_to_internal (script->charset, vbuffer) : NULL; - weechat_printf_y (buffer, y, "%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); - - free (vbuffer); -} - -/* - * script_api_log_printf: add a message in WeeChat log file - */ - -void -script_api_log_printf (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *format, ...) -{ - char *buf2; - - weechat_va_format (format); - if (!vbuffer) - return; - - buf2 = (script->charset && script->charset[0]) ? - weechat_iconv_to_internal (script->charset, vbuffer) : NULL; - weechat_log_printf ("%s", (buf2) ? buf2 : vbuffer); - if (buf2) - free (buf2); - - free (vbuffer); -} - -/* - * script_api_hook_command: hook a command - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_command (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, const char *description, - const char *args, const char *args_description, - const char *completion, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - int argc, char **argv, - char **argv_eol), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_command (command, description, args, - args_description, completion, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_command_run: hook a command_run - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - const char *command), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_command_run (command, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_timer: hook a timer - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int interval, int align_second, int max_calls, - int (*callback)(void *data, - int remaining_calls), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_timer (interval, align_second, max_calls, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_fd: hook a fd - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int fd, int flag_read, int flag_write, - int flag_exception, - int (*callback)(void *data, int fd), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_fd (fd, flag_read, flag_write, flag_exception, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_process_hashtable: hook a process - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_process_hashtable (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - struct t_hashtable *options, - int timeout, - int (*callback)(void *data, - const char *command, - int return_code, - const char *out, - const char *err), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_process_hashtable (command, options, timeout, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_process: hook a process - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_process (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - int timeout, - int (*callback)(void *data, - const char *command, - int return_code, - const char *out, - const char *err), - const char *function, - const char *data) -{ - return script_api_hook_process_hashtable (weechat_plugin, script, command, - NULL, timeout, - callback, function, data); -} - -/* - * script_api_hook_connect: hook a connection - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_connect (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *proxy, const char *address, int port, - int sock, int ipv6, void *gnutls_sess, - void *gnutls_cb, int gnutls_dhkey_size, - const char *gnutls_priorities, - const char *local_hostname, - int (*callback)(void *data, int status, - int gnutls_rc, - const char *error, - const char *ip_address), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_connect (proxy, address, port, sock, ipv6, - gnutls_sess, gnutls_cb, gnutls_dhkey_size, - gnutls_priorities, local_hostname, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_print: hook a print - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_print (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - const char *tags, const char *message, int strip_colors, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, - const char *message), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_print (buffer, tags, message, strip_colors, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_signal: hook a signal - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *signal, - int (*callback)(void *data, const char *signal, - const char *type_data, - void *signal_data), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_signal (signal, callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_hsignal: hook a hsignal - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *signal, - int (*callback)(void *data, const char *signal, - struct t_hashtable *hashtable), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_hsignal (signal, callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_config: hook a config option - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_config (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, - int (*callback)(void *data, const char *option, - const char *value), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_config (option, callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_completion: hook a completion - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *completion, - const char *description, - int (*callback)(void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_completion (completion, description, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_modifier: hook a modifier - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *modifier, - char *(*callback)(void *data, const char *modifier, - const char *modifier_data, - const char *string), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_modifier (modifier, callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_info: hook an info - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_info (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *info_name, - const char *description, - const char *args_description, - const char *(*callback)(void *data, - const char *info_name, - const char *arguments), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_info (info_name, description, args_description, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_info_hashtable: hook an info_hashtable - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_info_hashtable (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *info_name, - const char *description, - const char *args_description, - const char *output_description, - struct t_hashtable *(*callback)(void *data, - const char *info_name, - struct t_hashtable *hashtable), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_info_hashtable (info_name, description, - args_description, - output_description, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_infolist: hook an infolist - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *infolist_name, - const char *description, - const char *pointer_description, - const char *args_description, - struct t_infolist *(*callback)(void *data, - const char *infolist_name, - void *pointer, - const char *arguments), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_infolist (infolist_name, description, - pointer_description, args_description, - callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_hook_focus: hook a focus - * return new hook, NULL if error - */ - -struct t_hook * -script_api_hook_focus (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *area, - struct t_hashtable *(*callback)(void *data, - struct t_hashtable *info), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_hook *new_hook; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_hook = weechat_hook_focus (area, callback, script_cb); - if (new_hook) - { - weechat_hook_set (new_hook, "subplugin", script->name); - script_cb->hook = new_hook; - } - else - script_callback_remove (script, script_cb); - - return new_hook; -} - -/* - * script_api_unhook: unhook something - */ - -void -script_api_unhook (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_hook *hook) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !hook) - return; - - weechat_unhook (hook); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->hook == hook) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_unhook_all: remove all hooks from a script - */ - -void -script_api_unhook_all (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->hook) - { - weechat_unhook (ptr_script_cb->hook); - script_callback_remove (script, ptr_script_cb); - } - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_buffer_new: create a new buffer - */ - -struct t_gui_buffer * -script_api_buffer_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - int (*input_callback)(void *data, - struct t_gui_buffer *buffer, - const char *input_data), - const char *function_input, - const char *data_input, - int (*close_callback)(void *data, - struct t_gui_buffer *buffer), - const char *function_close, - const char *data_close) -{ - struct t_script_callback *script_cb_input; - struct t_script_callback *script_cb_close; - struct t_gui_buffer *new_buffer; - - script_cb_input = script_callback_add (script, function_input, data_input); - script_cb_close = script_callback_add (script, function_close, data_close); - if (!script_cb_input || !script_cb_close) - { - if (script_cb_input) - script_callback_remove (script, script_cb_input); - if (script_cb_close) - script_callback_remove (script, script_cb_close); - return NULL; - } - - new_buffer = weechat_buffer_new (name, - (function_input && function_input[0]) ? input_callback : NULL, - (function_input && function_input[0]) ? script_cb_input : NULL, - (function_close && function_close[0]) ? close_callback : NULL, - (function_close && function_close[0]) ? script_cb_close : NULL); - if (new_buffer) - { - script_cb_input->buffer = new_buffer; - script_cb_close->buffer = new_buffer; - - /* used when upgrading weechat, to set callbacks */ - weechat_buffer_set (new_buffer, "localvar_set_script_name", script->name); - weechat_buffer_set (new_buffer, "localvar_set_script_input_cb", function_input); - weechat_buffer_set (new_buffer, "localvar_set_script_input_cb_data", data_input); - weechat_buffer_set (new_buffer, "localvar_set_script_close_cb", function_close); - weechat_buffer_set (new_buffer, "localvar_set_script_close_cb_data", data_close); - } - else - { - script_callback_remove (script, script_cb_input); - script_callback_remove (script, script_cb_close); - } - - return new_buffer; -} - -/* - * script_api_buffer_close: close a buffer - */ - -void -script_api_buffer_close (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !buffer) - return; - - weechat_buffer_close (buffer); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->buffer == buffer) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_bar_item_new: add a new bar item - */ - -struct t_gui_bar_item * -script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - char *(*build_callback)(void *data, - struct t_gui_bar_item *item, - struct t_gui_window *window), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - struct t_gui_bar_item *new_item; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return NULL; - - new_item = weechat_bar_item_new (name, - (function && function[0]) ? build_callback : NULL, - (function && function[0]) ? script_cb : NULL); - if (new_item) - script_cb->bar_item = new_item; - else - script_callback_remove (script, script_cb); - - return new_item; -} - -/* - * script_api_bar_item_remove: remove a bar item - */ - -void -script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_bar_item *item) -{ - struct t_script_callback *ptr_script_cb, *next_callback; - - if (!weechat_plugin || !script || !item) - return; - - weechat_bar_item_remove (item); - - ptr_script_cb = script->callbacks; - while (ptr_script_cb) - { - next_callback = ptr_script_cb->next_callback; - - if (ptr_script_cb->bar_item == item) - script_callback_remove (script, ptr_script_cb); - - ptr_script_cb = next_callback; - } -} - -/* - * script_api_command: execute a command (simulate user entry) - */ - -void -script_api_command (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, const char *command) -{ - char *command2; - - command2 = (script->charset && script->charset[0]) ? - weechat_iconv_to_internal (script->charset, command) : NULL; - - weechat_command (buffer, (command2) ? command2 : command); - - if (command2) - free (command2); -} - -/* - * script_api_config_get_plugin: get a value of a script option - * format in file is "plugin.script.option" - */ - -const char * -script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option) -{ - char *option_fullname; - const char *return_value; - - option_fullname = malloc ((strlen (script->name) + - strlen (option) + 2)); - if (!option_fullname) - return NULL; - - strcpy (option_fullname, script->name); - strcat (option_fullname, "."); - strcat (option_fullname, option); - - return_value = weechat_config_get_plugin (option_fullname); - free (option_fullname); - - return return_value; -} - -/* - * script_api_config_is_set_plugin: check if a script option is set - */ - -int -script_api_config_is_set_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option) -{ - char *option_fullname; - int return_code; - - option_fullname = malloc ((strlen (script->name) + - strlen (option) + 2)); - if (!option_fullname) - return 0; - - strcpy (option_fullname, script->name); - strcat (option_fullname, "."); - strcat (option_fullname, option); - - return_code = weechat_config_is_set_plugin (option_fullname); - free (option_fullname); - - return return_code; -} - -/* - * script_api_config_set_plugin: set value of a script config option - * format in file is "plugin.script.option" - */ - -int -script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, const char *value) -{ - char *option_fullname; - int return_code; - - option_fullname = malloc ((strlen (script->name) + - strlen (option) + 2)); - if (!option_fullname) - return 0; - - strcpy (option_fullname, script->name); - strcat (option_fullname, "."); - strcat (option_fullname, option); - - return_code = weechat_config_set_plugin (option_fullname, value); - free (option_fullname); - - return return_code; -} - -/* - * script_api_config_set_plugin: set value of a script config option - * format in file is "plugin.script.option" - */ - -void -script_api_config_set_desc_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, const char *description) -{ - char *option_fullname; - - option_fullname = malloc ((strlen (script->name) + - strlen (option) + 2)); - if (!option_fullname) - return; - - strcpy (option_fullname, script->name); - strcat (option_fullname, "."); - strcat (option_fullname, option); - - weechat_config_set_desc_plugin (option_fullname, description); - free (option_fullname); -} - -/* - * script_api_config_unset_plugin: unset script config option - * format in file is "plugin.script.option" - */ - -int -script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option) -{ - char *option_fullname; - int return_code; - - option_fullname = malloc ((strlen (script->name) + - strlen (option) + 2)); - if (!option_fullname) - return 0; - - strcpy (option_fullname, script->name); - strcat (option_fullname, "."); - strcat (option_fullname, option); - - return_code = weechat_config_unset_plugin (option_fullname); - free (option_fullname); - - return return_code; -} - -/* - * script_api_upgrade_read: read upgrade file - * return 1 if ok, 0 if error - */ - -int -script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_upgrade_file *upgrade_file, - int (*callback_read)(void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist), - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - int rc; - - if (!function || !function[0]) - return 0; - - script_cb = script_callback_add (script, function, data); - if (!script_cb) - return 0; - script_cb->upgrade_file = upgrade_file; - - rc = weechat_upgrade_read (upgrade_file, - callback_read, - script_cb); - - script_callback_remove (script, script_cb); - - return rc; -} diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h deleted file mode 100644 index c60f10a70..000000000 --- a/src/plugins/scripts/script-api.h +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_SCRIPT_API_H -#define __WEECHAT_SCRIPT_API_H 1 - -extern void script_api_charset_set (struct t_plugin_script *script, - const char *charset); -extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - int (*callback_reload)(void *data, - struct t_config_file *config_file), - const char *function, - const char *data); -extern struct t_config_section *script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file, - const char *name, - int user_can_add_options, - int user_can_delete_options, - int (*callback_read)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value), - const char *function_read, - const char *data_read, - int (*callback_write)(void *data, - struct t_config_file *config_file, - const char *section_name), - const char *function_write, - const char *data_write, - int (*callback_write_default)(void *data, - struct t_config_file *config_file, - const char *section_name), - const char *function_write_default, - const char *data_write_default, - int (*callback_create_option)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value), - const char *function_create_option, - const char *data_create_option, - int (*callback_delete_option)(void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option), - const char *function_delete_option, - const char *data_delete_option); -extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file, - struct t_config_section *section, - const char *name, - const char *type, - const char *description, - const char *string_values, - int min, int max, - const char *default_value, - const char *value, - int null_value_allowed, - int (*callback_check_value)(void *data, - struct t_config_option *option, - const char *value), - const char *function_check_value, - const char *data_check_value, - void (*callback_change)(void *data, - struct t_config_option *option), - const char *function_change, - const char *data_change, - void (*callback_delete)(void *data, - struct t_config_option *option), - const char *function_delete, - const char *data_delete); -extern void script_api_config_option_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_option *option); -extern void script_api_config_section_free_options (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_section *section); -extern void script_api_config_section_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_section *section); -extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_config_file *config_file); -extern void script_api_printf (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - const char *format, ...); -extern void script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - time_t date, const char *tags, - const char *format, ...); -extern void script_api_printf_y (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - int y, const char *format, ...); -extern void script_api_log_printf (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *format, ...); -extern struct t_hook *script_api_hook_command (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, const char *description, - const char *args, const char *args_description, - const char *completion, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - int argc, char **argv, - char **argv_eol), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - const char *command), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int interval, int align_second, - int max_calls, - int (*callback)(void *data, - int remaining_calls), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - int fd, int flag_read, - int flag_write, int flag_exception, - int (*callback)(void *data, int fd), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_process_hashtable (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - struct t_hashtable *options, - int timeout, - int (*callback)(void *data, - const char *command, - int return_code, - const char *out, - const char *err), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_process (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *command, - int timeout, - int (*callback)(void *data, - const char *command, - int return_code, - const char *out, - const char *err), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_connect (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *proxy, - const char *address, - int port, - int sock, - int ipv6, - void *gnutls_sess, - void *gnutls_cb, - int gnutls_dhkey_size, - const char *gnutls_priorities, - const char *local_hostname, - int (*callback)(void *data, - int status, - int gnutls_rc, - const char *error, - const char *ip_address), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - const char *tags, - const char *message, - int strip_colors, - int (*callback)(void *data, - struct t_gui_buffer *buffer, - time_t date, - int tags_count, - const char **tags, - int displayed, - int highlight, - const char *prefix, - const char *message), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *signal, - int (*callback)(void *data, - const char *signal, - const char *type_data, - void *signal_data), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *signal, - int (*callback)(void *data, - const char *signal, - struct t_hashtable *hashtable), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, - int (*callback)(void *data, - const char *option, - const char *value), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *completion, - const char *description, - int (*callback)(void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *modifier, - char *(*callback)(void *data, - const char *modifier, - const char *modifier_data, - const char *string), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_info (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *info_name, - const char *description, - const char *args_description, - const char *(*callback)(void *data, - const char *info_name, - const char *arguments), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_info_hashtable (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *info_name, - const char *description, - const char *args_description, - const char *output_description, - struct t_hashtable *(*callback)(void *data, - const char *info_name, - struct t_hashtable *hashtable), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *infolist_name, - const char *description, - const char *pointer_description, - const char *args_description, - struct t_infolist *(*callback)(void *data, - const char *infolist_name, - void *pointer, - const char *arguments), - const char *function, - const char *data); -extern struct t_hook *script_api_hook_focus (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *area, - struct t_hashtable *(*callback)(void *data, - struct t_hashtable *info), - const char *function, - const char *data); -extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_hook *hook); -extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script); -extern struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - int (*input_callback)(void *data, - struct t_gui_buffer *buffer, - const char *input_data), - const char *function_input, - const char *data_input, - int (*close_callback)(void *data, - struct t_gui_buffer *buffer), - const char *function_close, - const char *data_close); -extern void script_api_buffer_close (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer); -extern struct t_gui_bar_item *script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *name, - char *(*build_callback)(void *data, - struct t_gui_bar_item *item, - struct t_gui_window *window), - const char *function, - const char *data); -extern void script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_bar_item *item); -extern void script_api_command (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_gui_buffer *buffer, - const char *command); -extern const char *script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option); -extern int script_api_config_is_set_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option); -extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, const char *value); -extern void script_api_config_set_desc_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option, - const char *description); -extern int script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - const char *option); -extern int script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *script, - struct t_upgrade_file *upgrade_file, - int (*callback_read)(void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist), - const char *function, - const char *data); - -#endif /* __WEECHAT_SCRIPT_API_H */ diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c deleted file mode 100644 index 4c1fa7414..000000000 --- a/src/plugins/scripts/script-callback.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * script-callback.c: script callbacks management - */ - -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include "../weechat-plugin.h" -#include "script.h" -#include "script-callback.h" - - -/* - * script_callback_alloc: allocate a new callback and initializes it - */ - -struct t_script_callback * -script_callback_alloc () -{ - struct t_script_callback *new_script_callback; - - new_script_callback = malloc (sizeof (*new_script_callback)); - if (new_script_callback) - { - new_script_callback->script = NULL; - new_script_callback->function = NULL; - new_script_callback->data = NULL; - new_script_callback->config_file = NULL; - new_script_callback->config_section = NULL; - new_script_callback->config_option = NULL; - new_script_callback->hook = NULL; - new_script_callback->buffer = NULL; - new_script_callback->bar_item = NULL; - new_script_callback->upgrade_file = NULL; - return new_script_callback; - } - - return NULL; -} - -/* - * script_callback_add: allocate a new callback, initialize it - * (script/function/data) and add it to list - * return pointer to new callback or NULL if error - */ - -struct t_script_callback * -script_callback_add (struct t_plugin_script *script, - const char *function, - const char *data) -{ - struct t_script_callback *script_cb; - if (!script) - return NULL; - - script_cb = script_callback_alloc (); - if (!script_cb) - return NULL; - - /* initialize callback */ - script_cb->script = script; - script_cb->function = (function) ? strdup (function) : NULL; - script_cb->data = (data) ? strdup (data) : NULL; - - /* add callback to list */ - if (script->callbacks) - script->callbacks->prev_callback = script_cb; - script_cb->prev_callback = NULL; - script_cb->next_callback = script->callbacks; - script->callbacks = script_cb; - - return script_cb; -} - -/* - * script_callback_free_data: free data of a script callback - */ - -void -script_callback_free_data (struct t_script_callback *script_callback) -{ - if (script_callback->function) - free (script_callback->function); - if (script_callback->data) - free (script_callback->data); -} - -/* - * script_callback_remove: remove a callback from a script - */ - -void -script_callback_remove (struct t_plugin_script *script, - struct t_script_callback *script_callback) -{ - /* remove callback from list */ - if (script_callback->prev_callback) - (script_callback->prev_callback)->next_callback = - script_callback->next_callback; - if (script_callback->next_callback) - (script_callback->next_callback)->prev_callback = - script_callback->prev_callback; - if (script->callbacks == script_callback) - script->callbacks = script_callback->next_callback; - - script_callback_free_data (script_callback); - - free (script_callback); -} - -/* - * script_callback_remove_all: remove all callbacks from a script - */ - -void -script_callback_remove_all (struct t_plugin_script *script) -{ - while (script->callbacks) - { - script_callback_remove (script, script->callbacks); - } -} - -/* - * script_callback_print_log: print callback infos in log (usually for crash dump) - */ - -void -script_callback_print_log (struct t_weechat_plugin *weechat_plugin, - struct t_script_callback *script_callback) -{ - weechat_log_printf (""); - weechat_log_printf (" [callback (addr:0x%lx)]", script_callback); - weechat_log_printf (" script. . . . . . . : 0x%lx", script_callback->script); - weechat_log_printf (" function. . . . . . : '%s'", script_callback->function); - weechat_log_printf (" data. . . . . . . . : '%s'", script_callback->data); - weechat_log_printf (" config_file . . . . : 0x%lx", script_callback->config_file); - weechat_log_printf (" config_section. . . : 0x%lx", script_callback->config_section); - weechat_log_printf (" config_option . . . : 0x%lx", script_callback->config_option); - weechat_log_printf (" hook. . . . . . . . : 0x%lx", script_callback->hook); - weechat_log_printf (" buffer. . . . . . . : 0x%lx", script_callback->buffer); - weechat_log_printf (" bar_item. . . . . . : 0x%lx", script_callback->bar_item); - weechat_log_printf (" upgrade_file. . . . : 0x%lx", script_callback->upgrade_file); - weechat_log_printf (" prev_callback . . . : 0x%lx", script_callback->prev_callback); - weechat_log_printf (" next_callback . . . : 0x%lx", script_callback->next_callback); -} diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h deleted file mode 100644 index f48fdb13c..000000000 --- a/src/plugins/scripts/script-callback.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_SCRIPT_CALLBACK_H -#define __WEECHAT_SCRIPT_CALLBACK_H 1 - -struct t_script_callback -{ - void *script; /* pointer to script */ - char *function; /* script function called */ - char *data; /* data string for callback */ - struct t_config_file *config_file; /* not NULL for config file */ - struct t_config_section *config_section; /* not NULL for config section */ - struct t_config_option *config_option; /* not NULL for config option */ - struct t_hook *hook; /* not NULL for hook */ - struct t_gui_buffer *buffer; /* not NULL for buffer */ - struct t_gui_bar_item *bar_item; /* not NULL for bar item */ - struct t_upgrade_file *upgrade_file; /* not NULL for upgrade file */ - struct t_script_callback *prev_callback; /* link to next callback */ - struct t_script_callback *next_callback; /* link to previous callback */ -}; - -extern struct t_script_callback *script_callback_add (struct t_plugin_script *script, - const char *function, - const char *data); -extern void script_callback_remove (struct t_plugin_script *script, - struct t_script_callback *script_callback); -extern void script_callback_remove_all (struct t_plugin_script *script); -extern void script_callback_print_log (struct t_weechat_plugin *weechat_plugin, - struct t_script_callback *script_callback); - -#endif /* __WEECHAT_SCRIPT_CALLBACK_H */ diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c deleted file mode 100644 index 7f5ec2d2e..000000000 --- a/src/plugins/scripts/script.c +++ /dev/null @@ -1,1308 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * script.c: common functions used by script plugins (perl/python/..) - */ - -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <libgen.h> -#include <string.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <dirent.h> - -#include "../weechat-plugin.h" -#include "script.h" -#include "script-callback.h" - - -#define SCRIPT_OPTION_CHECK_LICENSE "check_license" - -int script_option_check_license = 0; - - -/* - * script_config_read: read script configuration - */ - -void -script_config_read (struct t_weechat_plugin *weechat_plugin) -{ - const char *string; - - string = weechat_config_get_plugin (SCRIPT_OPTION_CHECK_LICENSE); - if (!string) - { - weechat_config_set_plugin (SCRIPT_OPTION_CHECK_LICENSE, "on"); - string = weechat_config_get_plugin (SCRIPT_OPTION_CHECK_LICENSE); - } - if (string && (weechat_config_string_to_boolean (string) > 0)) - script_option_check_license = 1; - else - script_option_check_license = 0; -} - -/* - * script_config_cb: callback called when config option is changed - */ - -int -script_config_cb (void *data, const char *option, const char *value) -{ - /* make C compiler happy */ - (void) option; - (void) value; - - script_config_read (data); - - return WEECHAT_RC_OK; -} - -/* - * script_init: initialize script plugin - */ - -void -script_init (struct t_weechat_plugin *weechat_plugin, int argc, char *argv[], - struct t_plugin_script_init *init) -{ - char *string, *completion; - char signal_name[128]; - int length, i, auto_load_scripts; - - /* read script configuration */ - script_config_read (weechat_plugin); - - /* add hook for config option */ - length = strlen (weechat_plugin->name) + 64; - string = malloc (length); - if (string) - { - snprintf (string, length, "plugins.var.%s.%s", - weechat_plugin->name, SCRIPT_OPTION_CHECK_LICENSE); - weechat_hook_config (string, &script_config_cb, weechat_plugin); - free (string); - } - - /* create directories in WeeChat home */ - weechat_mkdir_home (weechat_plugin->name, 0755); - length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1; - string = malloc (length); - if (string) - { - snprintf (string, length, "%s/autoload", weechat_plugin->name); - weechat_mkdir_home (string, 0755); - free (string); - } - - /* add command */ - completion = NULL; - length = strlen (weechat_plugin->name) + 16; - string = malloc (length); - if (string) - { - snprintf (string, length, "%%(%s_script)", - weechat_plugin->name); - completion = weechat_string_replace ("list %s" - " || listfull %s" - " || load %(filename)" - " || autoload" - " || reload %s" - " || unload %s", - "%s", - string); - } - weechat_hook_command (weechat_plugin->name, - N_("list/load/unload scripts"), - N_("list|listfull [<name>]" - " || load <filename>" - " || autoload" - " || reload|unload [<name>]"), - N_(" list: list loaded scripts\n" - "listfull: list loaded scripts (verbose)\n" - " load: load a script\n" - "autoload: load all scripts in \"autoload\" " - "directory\n" - " reload: reload a script (if no name given, " - "unload all scripts, then load all scripts in " - "\"autoload\" directory)\n" - " unload: unload a script (if no name given, " - "unload all scripts)\n" - "filename: script (file) to load\n" - " name: a script name (name used in call to " - "\"register\" function)\n\n" - "Without argument, this command " - "lists all loaded scripts."), - completion, - init->callback_command, NULL); - if (string) - free (string); - if (completion) - free (completion); - - /* add completion and infolist */ - length = strlen (weechat_plugin->name) + 16; - string = malloc (length); - if (string) - { - snprintf (string, length, "%s_script", weechat_plugin->name); - weechat_hook_completion (string, N_("list of scripts"), - init->callback_completion, NULL); - weechat_hook_infolist (string, N_("list of scripts"), - N_("script pointer (optional)"), - N_("script name (can start or end with \"*\" as wildcard) (optional)"), - init->callback_infolist, NULL); - free (string); - } - - /* add signal for "debug_dump" */ - weechat_hook_signal ("debug_dump", init->callback_signal_debug_dump, NULL); - - /* add signal for "buffer_closed" */ - weechat_hook_signal ("buffer_closed", - init->callback_signal_buffer_closed, NULL); - - /* add signal for a script action (install/remove) */ - snprintf (signal_name, sizeof (signal_name), "%s_script_install", - weechat_plugin->name); - weechat_hook_signal (signal_name, - init->callback_signal_script_action, NULL); - snprintf (signal_name, sizeof (signal_name), "%s_script_remove", - weechat_plugin->name); - weechat_hook_signal (signal_name, - init->callback_signal_script_action, NULL); - - /* parse arguments */ - auto_load_scripts = 1; - for (i = 0; i < argc; i++) - { - if ((strcmp (argv[i], "-s") == 0) - || (strcmp (argv[i], "--no-script") == 0)) - { - auto_load_scripts = 0; - } - } - - /* autoload scripts */ - if (auto_load_scripts) - { - script_auto_load (weechat_plugin, init->callback_load_file); - } -} - -/* - * script_valid: check if a script pointer exists - * return 1 if script exists - * 0 if script is not found - */ - -int -script_valid (struct t_plugin_script *scripts, - struct t_plugin_script *script) -{ - struct t_plugin_script *ptr_script; - - if (!script) - return 0; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - if (ptr_script == script) - return 1; - } - - /* script not found */ - return 0; -} - -/* - * script_ptr2str: convert pointer to string for usage in a script - * (any language) - * WARNING: result has to be free() after use - */ - -char * -script_ptr2str (void *pointer) -{ - char pointer_str[128]; - - if (!pointer) - return strdup (""); - - snprintf (pointer_str, sizeof (pointer_str), - "0x%lx", (long unsigned int)pointer); - - return strdup (pointer_str); -} - -/* - * script_str2ptr: convert string to pointer for usage outside script - */ - -void * -script_str2ptr (struct t_weechat_plugin *weechat_plugin, - const char *script_name, const char *function_name, - const char *str_pointer) -{ - long unsigned int value; - int rc; - struct t_gui_buffer *ptr_buffer; - - if (!str_pointer || !str_pointer[0]) - return NULL; - - if ((str_pointer[0] != '0') || (str_pointer[1] != 'x')) - goto invalid; - - rc = sscanf (str_pointer + 2, "%lx", &value); - if ((rc != EOF) && (rc >= 1)) - return (void *)value; - -invalid: - if (weechat_plugin->debug >= 1) - { - ptr_buffer = weechat_buffer_search_main (); - if (ptr_buffer) - { - weechat_buffer_set (ptr_buffer, "print_hooks_enabled", "0"); - weechat_printf (NULL, - _("%s%s: warning, invalid pointer (\"%s\") for " - "function \"%s\" (script: %s)"), - weechat_prefix ("error"), weechat_plugin->name, - str_pointer, function_name, script_name); - weechat_buffer_set (ptr_buffer, "print_hooks_enabled", "1"); - } - } - return NULL; -} - -/* - * script_auto_load: auto-load all scripts in a directory - */ - -void -script_auto_load (struct t_weechat_plugin *weechat_plugin, - void (*callback)(void *data, const char *filename)) -{ - const char *dir_home; - char *dir_name; - int dir_length; - - /* build directory, adding WeeChat home */ - dir_home = weechat_info_get ("weechat_dir", ""); - if (!dir_home) - return; - dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16; - dir_name = malloc (dir_length); - if (!dir_name) - return; - - snprintf (dir_name, dir_length, - "%s/%s/autoload", dir_home, weechat_plugin->name); - weechat_exec_on_files (dir_name, 0, NULL, callback); - - free (dir_name); -} - -/* - * script_search: search a script in list (by registered name) - */ - -struct t_plugin_script * -script_search (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, const char *name) -{ - struct t_plugin_script *ptr_script; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - if (weechat_strcasecmp (ptr_script->name, name) == 0) - return ptr_script; - } - - /* script not found */ - return NULL; -} - -/* - * script_search_by_full_name: search a script in list (by full name, for - * example "weeget.py") - */ - -struct t_plugin_script * -script_search_by_full_name (struct t_plugin_script *scripts, - const char *full_name) -{ - char *base_name; - struct t_plugin_script *ptr_script; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - base_name = basename (ptr_script->filename); - if (strcmp (base_name, full_name) == 0) - return ptr_script; - } - - /* script not found */ - return NULL; -} - -/* - * script_search_path: search path name of a script - */ - -char * -script_search_path (struct t_weechat_plugin *weechat_plugin, - const char *filename) -{ - char *final_name; - const char *dir_home, *dir_system; - int length; - struct stat st; - - if (filename[0] == '~') - return weechat_string_expand_home (filename); - - dir_home = weechat_info_get ("weechat_dir", ""); - if (dir_home) - { - /* try WeeChat user's autoload dir */ - length = strlen (dir_home) + strlen (weechat_plugin->name) + 8 + - strlen (filename) + 16; - final_name = malloc (length); - if (final_name) - { - snprintf (final_name, length, - "%s/%s/autoload/%s", - dir_home, weechat_plugin->name, filename); - if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - return final_name; - free (final_name); - } - - /* try WeeChat language user's dir */ - length = strlen (dir_home) + strlen (weechat_plugin->name) + - strlen (filename) + 16; - final_name = malloc (length); - if (final_name) - { - snprintf (final_name, length, - "%s/%s/%s", dir_home, weechat_plugin->name, filename); - if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - return final_name; - free (final_name); - } - - /* try WeeChat user's dir */ - length = strlen (dir_home) + strlen (filename) + 16; - final_name = malloc (length); - if (final_name) - { - snprintf (final_name, length, - "%s/%s", dir_home, filename); - if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - return final_name; - free (final_name); - } - } - - /* try WeeChat system dir */ - dir_system = weechat_info_get ("weechat_sharedir", ""); - if (dir_system) - { - length = strlen (dir_system) + strlen (weechat_plugin->name) + - strlen (filename) + 16; - final_name = malloc (length); - if (final_name) - { - snprintf (final_name,length, - "%s/%s/%s", dir_system, weechat_plugin->name, filename); - if ((stat (final_name, &st) == 0) && (st.st_size > 0)) - return final_name; - free (final_name); - } - } - - return strdup (filename); -} - -/* - * script_find_pos: find position for a script (for sorting scripts list) - */ - -struct t_plugin_script * -script_find_pos (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - struct t_plugin_script *script) -{ - struct t_plugin_script *ptr_script; - - for (ptr_script = scripts; ptr_script; ptr_script = ptr_script->next_script) - { - if (weechat_strcasecmp (script->name, ptr_script->name) < 0) - return ptr_script; - } - return NULL; -} - -/* - * script_insert_sorted: insert a script in list, keeping sort on name - */ - -void -script_insert_sorted (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - struct t_plugin_script **last_script, - struct t_plugin_script *script) -{ - struct t_plugin_script *pos_script; - - if (*scripts) - { - pos_script = script_find_pos (weechat_plugin, *scripts, script); - - if (pos_script) - { - /* insert script into the list (before script found) */ - script->prev_script = pos_script->prev_script; - script->next_script = pos_script; - if (pos_script->prev_script) - (pos_script->prev_script)->next_script = script; - else - *scripts = script; - pos_script->prev_script = script; - } - else - { - /* add script to the end */ - script->prev_script = *last_script; - script->next_script = NULL; - (*last_script)->next_script = script; - *last_script = script; - } - } - else - { - /* first script in list */ - script->prev_script = NULL; - script->next_script = NULL; - *scripts = script; - *last_script = script; - } -} - -/* - * script_add: add a script to list of scripts - */ - -struct t_plugin_script * -script_add (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - struct t_plugin_script **last_script, - const char *filename, const char *name, const char *author, const char *version, - const char *license, const char *description, const char *shutdown_func, - const char *charset) -{ - struct t_plugin_script *new_script; - - if (strchr (name, ' ')) - { - weechat_printf (NULL, - _("%s: error loading script \"%s\" (bad name, spaces " - "are forbidden)"), - weechat_plugin->name, name); - return NULL; - } - - if (script_option_check_license - && (weechat_strcmp_ignore_chars (weechat_plugin->license, license, - "0123456789-.,/\\()[]{}", 0) != 0)) - { - weechat_printf (NULL, - _("%s%s: warning, license \"%s\" for script \"%s\" " - "differs from plugin license (\"%s\")"), - weechat_prefix ("error"), weechat_plugin->name, - license, name, weechat_plugin->license); - } - - new_script = malloc (sizeof (*new_script)); - if (new_script) - { - new_script->filename = strdup (filename); - new_script->interpreter = NULL; - new_script->name = strdup (name); - new_script->author = strdup (author); - new_script->version = strdup (version); - new_script->license = strdup (license); - new_script->description = strdup (description); - new_script->shutdown_func = (shutdown_func) ? - strdup (shutdown_func) : NULL; - new_script->charset = (charset) ? strdup (charset) : NULL; - new_script->callbacks = NULL; - new_script->unloading = 0; - - script_insert_sorted (weechat_plugin, scripts, last_script, new_script); - - return new_script; - } - - weechat_printf (NULL, - _("%s: error loading script \"%s\" (not enough memory)"), - weechat_plugin->name, name); - - return NULL; -} - -/* - * script_set_buffer_callbacks: restore buffers callbacks (input and - * close) for buffers created by script - * plugin - */ - -void -script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - struct t_plugin_script *script, - int (*callback_buffer_input) (void *data, - struct t_gui_buffer *buffer, - const char *input_data), - int (*callback_buffer_close) (void *data, - struct t_gui_buffer *buffer)) -{ - struct t_infolist *infolist; - struct t_gui_buffer *ptr_buffer; - const char *script_name, *str_script_input_cb, *str_script_input_cb_data; - const char *str_script_close_cb, *str_script_close_cb_data; - struct t_plugin_script *ptr_script; - struct t_script_callback *script_cb_input; - struct t_script_callback *script_cb_close; - - infolist = weechat_infolist_get ("buffer", NULL, NULL); - if (infolist) - { - while (weechat_infolist_next (infolist)) - { - if (weechat_infolist_pointer (infolist, "plugin") == weechat_plugin) - { - ptr_buffer = weechat_infolist_pointer (infolist, "pointer"); - script_name = weechat_buffer_get_string (ptr_buffer, "localvar_script_name"); - if (script_name && script_name[0]) - { - ptr_script = script_search (weechat_plugin, scripts, - script_name); - if (ptr_script && (ptr_script == script)) - { - str_script_input_cb = weechat_buffer_get_string (ptr_buffer, - "localvar_script_input_cb"); - str_script_input_cb_data = weechat_buffer_get_string (ptr_buffer, - "localvar_script_input_cb_data"); - str_script_close_cb = weechat_buffer_get_string (ptr_buffer, - "localvar_script_close_cb"); - str_script_close_cb_data = weechat_buffer_get_string (ptr_buffer, - "localvar_script_close_cb_data"); - - if (str_script_input_cb && str_script_input_cb[0]) - { - script_cb_input = script_callback_add (ptr_script, - str_script_input_cb, - str_script_input_cb_data); - if (script_cb_input) - { - script_cb_input->buffer = ptr_buffer; - weechat_buffer_set_pointer (ptr_buffer, - "input_callback", - callback_buffer_input); - weechat_buffer_set_pointer (ptr_buffer, - "input_callback_data", - script_cb_input); - } - } - if (str_script_close_cb && str_script_close_cb[0]) - { - script_cb_close = script_callback_add (ptr_script, - str_script_close_cb, - str_script_close_cb_data); - if (script_cb_close) - { - script_cb_close->buffer = ptr_buffer; - weechat_buffer_set_pointer (ptr_buffer, - "close_callback", - callback_buffer_close); - weechat_buffer_set_pointer (ptr_buffer, - "close_callback_data", - script_cb_close); - } - } - } - } - } - } - weechat_infolist_free (infolist); - } -} - -/* - * script_remove_buffer_callbacks: remove callbacks for a buffer (called when a - * buffer is closed by user) - */ - -void -script_remove_buffer_callbacks (struct t_plugin_script *scripts, - struct t_gui_buffer *buffer) -{ - struct t_plugin_script *ptr_script; - struct t_script_callback *ptr_script_cb, *next_script_cb; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - /* - * do not remove buffer callbacks if script is being unloaded - * (because all callbacks will be removed anyway) - */ - if (!ptr_script->unloading) - { - ptr_script_cb = ptr_script->callbacks; - while (ptr_script_cb) - { - next_script_cb = ptr_script_cb->next_callback; - - if (ptr_script_cb->buffer == buffer) - script_callback_remove (ptr_script, ptr_script_cb); - - ptr_script_cb = next_script_cb; - } - } - } -} - -/* - * script_remove: remove a script from list of scripts - */ - -void -script_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - struct t_plugin_script **last_script, - struct t_plugin_script *script) -{ - struct t_script_callback *ptr_script_cb, *ptr_script_cb2; - - script->unloading = 1; - - for (ptr_script_cb = script->callbacks; ptr_script_cb; - ptr_script_cb = ptr_script_cb->next_callback) - { - /* free config file */ - if (ptr_script_cb->config_file) - { - if (weechat_config_boolean (weechat_config_get ("weechat.plugin.save_config_on_unload"))) - weechat_config_write (ptr_script_cb->config_file); - weechat_config_free (ptr_script_cb->config_file); - } - - /* unhook */ - if (ptr_script_cb->hook) - weechat_unhook (ptr_script_cb->hook); - - /* close buffer */ - if (ptr_script_cb->buffer) - weechat_buffer_close (ptr_script_cb->buffer); - - /* remove bar item */ - if (ptr_script_cb->bar_item) - weechat_bar_item_remove (ptr_script_cb->bar_item); - - /* - * remove same pointers in other callbacks - * (to not free 2 times with same pointer!) - */ - for (ptr_script_cb2 = ptr_script_cb->next_callback; ptr_script_cb2; - ptr_script_cb2 = ptr_script_cb2->next_callback) - { - if (ptr_script_cb2->config_file == ptr_script_cb->config_file) - ptr_script_cb2->config_file = NULL; - if (ptr_script_cb2->config_section == ptr_script_cb->config_section) - ptr_script_cb2->config_section = NULL; - if (ptr_script_cb2->config_option == ptr_script_cb->config_option) - ptr_script_cb2->config_option = NULL; - if (ptr_script_cb2->hook == ptr_script_cb->hook) - ptr_script_cb2->hook = NULL; - if (ptr_script_cb2->buffer == ptr_script_cb->buffer) - ptr_script_cb2->buffer = NULL; - if (ptr_script_cb2->bar_item == ptr_script_cb->bar_item) - ptr_script_cb2->bar_item = NULL; - if (ptr_script_cb2->upgrade_file == ptr_script_cb->upgrade_file) - ptr_script_cb2->upgrade_file = NULL; - } - } - - /* remove all callbacks created by this script */ - script_callback_remove_all (script); - - /* free data */ - if (script->filename) - free (script->filename); - if (script->name) - free (script->name); - if (script->author) - free (script->author); - if (script->version) - free (script->version); - if (script->license) - free (script->license); - if (script->description) - free (script->description); - if (script->shutdown_func) - free (script->shutdown_func); - if (script->charset) - free (script->charset); - - /* remove script from list */ - if (script->prev_script) - (script->prev_script)->next_script = script->next_script; - if (script->next_script) - (script->next_script)->prev_script = script->prev_script; - if (*scripts == script) - *scripts = script->next_script; - if (*last_script == script) - *last_script = script->prev_script; - - /* free script */ - free (script); -} - -/* - * script_completion: complete with list of scripts - */ - -void -script_completion (struct t_weechat_plugin *weechat_plugin, - struct t_gui_completion *completion, - struct t_plugin_script *scripts) -{ - struct t_plugin_script *ptr_script; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - weechat_hook_completion_list_add (completion, ptr_script->name, - 0, WEECHAT_LIST_POS_SORT); - } -} - -/* - * script_action_add: add script name for a plugin action - */ - -void -script_action_add (char **action_list, const char *name) -{ - int length; - char *action_list2; - - length = strlen (name); - - if (!(*action_list)) - { - *action_list = malloc (length + 1); - if (*action_list) - strcpy (*action_list, name); - } - else - { - action_list2 = realloc (*action_list, - strlen (*action_list) + 1 + length + 1); - if (!action_list2) - { - free (*action_list); - *action_list = NULL; - return; - } - *action_list = action_list2; - strcat (*action_list, ","); - strcat (*action_list, name); - } -} - -/* - * script_remove_file: remove script file(s) from disk - */ - -void -script_remove_file (struct t_weechat_plugin *weechat_plugin, const char *name, - int display_error_if_no_script_removed) -{ - int num_found, i; - char *path_script; - - num_found = 0; - i = 0; - while (i < 2) - { - path_script = script_search_path (weechat_plugin, name); - /* script not found? */ - if (!path_script || (strcmp (path_script, name) == 0)) - break; - num_found++; - if (unlink (path_script) == 0) - { - weechat_printf (NULL, _("%s: script removed: %s"), - weechat_plugin->name, - path_script); - } - else - { - weechat_printf (NULL, - _("%s%s: failed to remove script: %s " - "(%s)"), - weechat_prefix ("error"), - weechat_plugin->name, - path_script, - strerror (errno)); - break; - } - free (path_script); - i++; - } - if ((num_found == 0) && display_error_if_no_script_removed) - { - weechat_printf (NULL, - _("%s: script \"%s\" not found, nothing " - "was removed"), - weechat_plugin->name, - name); - } -} - -/* - * script_action_install: install some scripts (using comma separated list) - * this function does following tasks: - * 1. unload script (if script is loaded) - * 2. remove script file(s) - * 3. move script file from "install" dir to language dir - * 4. make link in autoload dir - * 5. load script - */ - -void -script_action_install (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void (*script_unload)(struct t_plugin_script *script), - int (*script_load)(const char *filename), - char **list) -{ - char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path; - char *symlink_path; - const char *dir_home, *dir_separator; - int argc, i, length, rc; - struct t_plugin_script *ptr_script; - - if (*list) - { - argv = weechat_string_split (*list, ",", 0, 0, &argc); - if (argv) - { - for (i = 0; i < argc; i++) - { - name = strdup (argv[i]); - if (name) - { - ptr_base_name = basename (name); - base_name = strdup (ptr_base_name); - if (base_name) - { - /* unload script, if script is loaded */ - ptr_script = script_search_by_full_name (scripts, base_name); - if (ptr_script) - (*script_unload) (ptr_script); - - /* remove script file(s) */ - script_remove_file (weechat_plugin, base_name, 0); - - /* move file from install dir to language dir */ - dir_home = weechat_info_get ("weechat_dir", ""); - length = strlen (dir_home) + strlen (weechat_plugin->name) + - strlen (base_name) + 16; - new_path = malloc (length); - if (new_path) - { - snprintf (new_path, length, "%s/%s/%s", - dir_home, weechat_plugin->name, base_name); - if (rename (name, new_path) == 0) - { - /* make link in autoload dir */ - length = strlen (dir_home) + - strlen (weechat_plugin->name) + 8 + - strlen (base_name) + 16; - autoload_path = malloc (length); - if (autoload_path) - { - snprintf (autoload_path, length, - "%s/%s/autoload/%s", - dir_home, weechat_plugin->name, - base_name); - dir_separator = weechat_info_get ("dir_separator", ""); - length = 2 + strlen (dir_separator) + - strlen (base_name) + 1; - symlink_path = malloc (length); - if (symlink_path) - { - snprintf (symlink_path, length, "..%s%s", - dir_separator, base_name); - rc = symlink (symlink_path, autoload_path); - (void) rc; - free (symlink_path); - } - free (autoload_path); - } - - /* load script */ - (*script_load) (new_path); - } - else - { - weechat_printf (NULL, - _("%s%s: failed to move script %s " - "to %s (%s)"), - weechat_prefix ("error"), - weechat_plugin->name, - name, - new_path, - strerror (errno)); - } - free (new_path); - } - free (base_name); - } - free (name); - } - } - weechat_string_free_split (argv); - } - free (*list); - *list = NULL; - } -} - -/* - * script_action_remove: remove some scripts (using comma separated list) - * this function does following tasks: - * 1. unload script (if script is loaded) - * 2. remove script file(s) - */ - -void -script_action_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void (*script_unload)(struct t_plugin_script *script), - char **list) -{ - char **argv; - int argc, i; - struct t_plugin_script *ptr_script; - - if (*list) - { - argv = weechat_string_split (*list, ",", 0, 0, &argc); - if (argv) - { - for (i = 0; i < argc; i++) - { - /* unload script, if script is loaded */ - ptr_script = script_search_by_full_name (scripts, argv[i]); - if (ptr_script) - (*script_unload) (ptr_script); - - /* remove script file(s) */ - script_remove_file (weechat_plugin, argv[i], 1); - } - weechat_string_free_split (argv); - } - free (*list); - *list = NULL; - } -} - -/* - * script_display_list: print list of scripts - */ - -void -script_display_list (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - const char *name, int full) -{ - struct t_plugin_script *ptr_script; - - weechat_printf (NULL, ""); - weechat_printf (NULL, - /* TRANSLATORS: "%s" is language (for example "perl") */ - _("%s scripts loaded:"), - weechat_plugin->name); - if (scripts) - { - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - if (!name || (weechat_strcasestr (ptr_script->name, name))) - { - weechat_printf (NULL, - " %s%s%s v%s - %s", - weechat_color ("chat_buffer"), - ptr_script->name, - weechat_color ("chat"), - ptr_script->version, - ptr_script->description); - if (full) - { - weechat_printf (NULL, - _(" file: %s"), - ptr_script->filename); - weechat_printf (NULL, - _(" written by \"%s\", license: %s"), - ptr_script->author, - ptr_script->license); - } - } - } - } - else - weechat_printf (NULL, _(" (none)")); -} - -/* - * script_display_short_list: print list of scripts on one line - */ - -void -script_display_short_list (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts) -{ - const char *scripts_loaded; - char *buf; - int length; - struct t_plugin_script *ptr_script; - - if (scripts) - { - /* TRANSLATORS: "%s" is language (for example "perl") */ - scripts_loaded = _("%s scripts loaded:"); - - length = strlen (scripts_loaded) + strlen (weechat_plugin->name) + 1; - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - length += strlen (ptr_script->name) + 2; - } - length++; - - buf = malloc (length); - if (buf) - { - snprintf (buf, length, scripts_loaded, weechat_plugin->name); - strcat (buf, " "); - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - strcat (buf, ptr_script->name); - if (ptr_script->next_script) - strcat (buf, ", "); - } - weechat_printf (NULL, "%s", buf); - free (buf); - } - } -} - -/* - * script_add_to_infolist: add a script in an infolist - * return 1 if ok, 0 if error - */ - -int -script_add_to_infolist (struct t_weechat_plugin *weechat_plugin, - struct t_infolist *infolist, - struct t_plugin_script *script) -{ - struct t_infolist_item *ptr_item; - - if (!infolist || !script) - return 0; - - ptr_item = weechat_infolist_new_item (infolist); - if (!ptr_item) - return 0; - - if (!weechat_infolist_new_var_pointer (ptr_item, "pointer", script)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "filename", script->filename)) - return 0; - if (!weechat_infolist_new_var_pointer (ptr_item, "interpreter", script->interpreter)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "name", script->name)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "author", script->author)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "version", script->version)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "license", script->license)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "description", script->description)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "shutdown_func", script->shutdown_func)) - return 0; - if (!weechat_infolist_new_var_string (ptr_item, "charset", script->charset)) - return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "unloading", script->unloading)) - return 0; - - return 1; -} - -/* - * script_infolist_list_scripts: build infolist with list of scripts - */ - -struct t_infolist * -script_infolist_list_scripts (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void *pointer, - const char *arguments) -{ - struct t_infolist *ptr_infolist; - struct t_plugin_script *ptr_script; - - if (pointer && !script_valid (scripts, pointer)) - return NULL; - - ptr_infolist = weechat_infolist_new (); - if (ptr_infolist) - { - if (pointer) - { - /* build list with only one script */ - if (!script_add_to_infolist (weechat_plugin, - ptr_infolist, pointer)) - { - weechat_infolist_free (ptr_infolist); - return NULL; - } - return ptr_infolist; - } - else - { - /* build list with all scripts matching arguments */ - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - if (!arguments || !arguments[0] - || weechat_string_match (ptr_script->name, arguments, 0)) - { - if (!script_add_to_infolist (weechat_plugin, - ptr_infolist, ptr_script)) - { - weechat_infolist_free (ptr_infolist); - return NULL; - } - } - } - return ptr_infolist; - } - } - - return NULL; -} - -/* - * script_end: end script plugin - */ - -void -script_end (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - void (*callback_unload_all)()) -{ - int scripts_loaded; - - scripts_loaded = (*scripts) ? 1 : 0; - - (void)(callback_unload_all) (); - - if (scripts_loaded) - { - weechat_printf (NULL, _("%s: scripts unloaded"), - weechat_plugin->name); - } -} - -/* - * script_print_log: print script infos in log (usually for crash dump) - */ - -void -script_print_log (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts) -{ - struct t_plugin_script *ptr_script; - struct t_script_callback *ptr_script_cb; - - weechat_log_printf (""); - weechat_log_printf ("***** \"%s\" plugin dump *****", - weechat_plugin->name); - - for (ptr_script = scripts; ptr_script; - ptr_script = ptr_script->next_script) - { - weechat_log_printf (""); - weechat_log_printf ("[script %s (addr:0x%lx)]", ptr_script->name, ptr_script); - weechat_log_printf (" filename. . . . . . : '%s'", ptr_script->filename); - weechat_log_printf (" interpreter . . . . : 0x%lx", ptr_script->interpreter); - weechat_log_printf (" name. . . . . . . . : '%s'", ptr_script->name); - weechat_log_printf (" author. . . . . . . : '%s'", ptr_script->author); - weechat_log_printf (" version . . . . . . : '%s'", ptr_script->version); - weechat_log_printf (" license . . . . . . : '%s'", ptr_script->license); - weechat_log_printf (" description . . . . : '%s'", ptr_script->description); - weechat_log_printf (" shutdown_func . . . : '%s'", ptr_script->shutdown_func); - weechat_log_printf (" charset . . . . . . : '%s'", ptr_script->charset); - weechat_log_printf (" callbacks . . . . . : 0x%lx", ptr_script->callbacks); - weechat_log_printf (" unloading . . . . . : %d", ptr_script->unloading); - weechat_log_printf (" prev_script . . . . : 0x%lx", ptr_script->prev_script); - weechat_log_printf (" next_script . . . . : 0x%lx", ptr_script->next_script); - - for (ptr_script_cb = ptr_script->callbacks; ptr_script_cb; - ptr_script_cb = ptr_script_cb->next_callback) - { - script_callback_print_log (weechat_plugin, ptr_script_cb); - } - } - - weechat_log_printf (""); - weechat_log_printf ("***** End of \"%s\" plugin dump *****", - weechat_plugin->name); -} diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h deleted file mode 100644 index f8373613e..000000000 --- a/src/plugins/scripts/script.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_SCRIPT_H -#define __WEECHAT_SCRIPT_H 1 - -/* constants which defines return types for weechat_<lang>_exec functions */ - -enum t_weechat_script_exec_type -{ - WEECHAT_SCRIPT_EXEC_INT = 0, - WEECHAT_SCRIPT_EXEC_STRING, - WEECHAT_SCRIPT_EXEC_HASHTABLE, -}; - -#define WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE 16 - -#define WEECHAT_SCRIPT_MSG_NOT_INIT(__current_script, \ - __function) \ - weechat_printf (NULL, \ - weechat_gettext("%s%s: unable to call function " \ - "\"%s\", script is not " \ - "initialized (script: %s)"), \ - weechat_prefix ("error"), weechat_plugin->name, \ - __function, \ - (__current_script) ? __current_script : "-"); -#define WEECHAT_SCRIPT_MSG_WRONG_ARGS(__current_script, \ - __function) \ - weechat_printf (NULL, \ - weechat_gettext("%s%s: wrong arguments for " \ - "function \"%s\" (script: %s)"), \ - weechat_prefix ("error"), weechat_plugin->name, \ - __function, \ - (__current_script) ? __current_script : "-"); - -struct t_plugin_script -{ - /* script variables */ - char *filename; /* name of script on disk */ - void *interpreter; /* interpreter for script */ - char *name; /* script name */ - char *author; /* author name/mail */ - char *version; /* plugin version */ - char *license; /* script license */ - char *description; /* plugin description */ - char *shutdown_func; /* function when script is unloaded*/ - char *charset; /* script charset */ - struct t_script_callback *callbacks; /* callbacks for script */ - int unloading; /* script is being unloaded */ - struct t_plugin_script *prev_script; /* link to previous script */ - struct t_plugin_script *next_script; /* link to next script */ -}; - -struct t_plugin_script_init -{ - int (*callback_command)(void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol); - int (*callback_completion)(void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion); - struct t_infolist *(*callback_infolist)(void *data, - const char *infolist_name, - void *pointer, - const char *arguments); - int (*callback_signal_debug_dump)(void *data, const char *signal, - const char *type_data, - void *signal_data); - int (*callback_signal_buffer_closed)(void *data, const char *signal, - const char *type_data, - void *signal_data); - int (*callback_signal_script_action)(void *data, const char *signal, - const char *type_data, - void *signal_data); - void (*callback_load_file)(void *data, const char *filename); -}; - -extern void script_init (struct t_weechat_plugin *weechat_plugin, - int argc, char *argv[], - struct t_plugin_script_init *init); -extern int script_valid (struct t_plugin_script *scripts, - struct t_plugin_script *script); -extern char *script_ptr2str (void *pointer); -extern void *script_str2ptr (struct t_weechat_plugin *weechat_plugin, - const char *script_name, const char *function_name, - const char *pointer_str); -extern void script_auto_load (struct t_weechat_plugin *weechat_plugin, - void (*callback)(void *data, const char *filename)); -extern struct t_plugin_script *script_search (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - const char *name); -extern char *script_search_path (struct t_weechat_plugin *weechat_plugin, - const char *filename); -extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - struct t_plugin_script **last_script, - const char *filename, const char *name, - const char *author, const char *version, - const char *license, const char *description, - const char *shutdown_func, const char *charset); -extern void script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - struct t_plugin_script *script, - int (*callback_buffer_input) (void *data, - struct t_gui_buffer *buffer, - const char *input_data), - int (*callback_buffer_close) (void *data, - struct t_gui_buffer *buffer)); -extern void script_remove_buffer_callbacks (struct t_plugin_script *scripts, - struct t_gui_buffer *buffer); -extern void script_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - struct t_plugin_script **last_script, - struct t_plugin_script *script); -extern void script_completion (struct t_weechat_plugin *weechat_plugin, - struct t_gui_completion *completion, - struct t_plugin_script *scripts); -extern void script_action_add (char **action_list, const char *name); -extern void script_action_install (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void (*script_unload)(struct t_plugin_script *script), - int (*script_load)(const char *filename), - char **list); -extern void script_action_remove (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void (*script_unload)(struct t_plugin_script *script), - char **list); -extern void script_display_list (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - const char *name, int full); -extern void script_display_short_list (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts); -extern int script_add_to_infolist (struct t_weechat_plugin *weechat_plugin, - struct t_infolist *infolist, - struct t_plugin_script *script); -extern struct t_infolist *script_infolist_list_scripts (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts, - void *pointer, - const char *arguments); -extern void script_end (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script **scripts, - void (*callback_unload_all)()); -extern void script_print_log (struct t_weechat_plugin *weechat_plugin, - struct t_plugin_script *scripts); - -#endif /* __WEECHAT_SCRIPT_H */ diff --git a/src/plugins/scripts/tcl/CMakeLists.txt b/src/plugins/scripts/tcl/CMakeLists.txt deleted file mode 100644 index 9bd6d2b93..000000000 --- a/src/plugins/scripts/tcl/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> -# Copyright (C) 2008 Julien Louis <ptitlouis@sysif.net> -# Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -ADD_LIBRARY(tcl MODULE weechat-tcl.c weechat-tcl.h -weechat-tcl-api.c weechat-tcl-api.h) - -SET_TARGET_PROPERTIES(tcl PROPERTIES PREFIX "") - -IF(TCL_FOUND) - SET(CMAKE_REQUIRED_INCLUDES "${TCL_INCLUDE_PATH}") - SET(CMAKE_REQUIRED_LIBRARIES "${TCL_LIBRARY}") - - INCLUDE_DIRECTORIES(${TCL_INCLUDE_PATH}) - SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${TCL_LFLAGS}") - TARGET_LINK_LIBRARIES(tcl ${TCL_LIBRARY} weechat_scripts) - -ENDIF(TCL_FOUND) - -INSTALL(TARGETS tcl LIBRARY DESTINATION ${LIBDIR}/plugins) diff --git a/src/plugins/scripts/tcl/Makefile.am b/src/plugins/scripts/tcl/Makefile.am deleted file mode 100644 index 65d43b917..000000000 --- a/src/plugins/scripts/tcl/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> -# Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see <http://www.gnu.org/licenses/>. -# - -INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(TCL_CFLAGS) - -libdir = ${weechat_libdir}/plugins - -lib_LTLIBRARIES = tcl.la - -tcl_la_SOURCES = weechat-tcl.c \ - weechat-tcl.h \ - weechat-tcl-api.c \ - weechat-tcl-api.h -tcl_la_LDFLAGS = -module -tcl_la_LIBADD = ../lib_weechat_plugins_scripts.la $(TCL_LFLAGS) - -EXTRA_DIST = CMakeLists.txt diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c deleted file mode 100644 index 3af454fa6..000000000 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ /dev/null @@ -1,6629 +0,0 @@ -/* - * Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> - * Copyright (C) 2008 Julien Louis <ptitlouis@sysif.net> - * Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-tcl-api.c: tcl API functions - */ - -#undef _ - -#include <tcl.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "../script-api.h" -#include "../script-callback.h" -#include "weechat-tcl.h" - - -#define API_FUNC(__init, __name, __ret) \ - char *tcl_function_name = __name; \ - (void) clientData; \ - if (__init \ - && (!tcl_current_script || !tcl_current_script->name)) \ - { \ - WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, \ - tcl_function_name); \ - __ret; \ - } -#define API_WRONG_ARGS(__ret) \ - { \ - WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, \ - tcl_function_name); \ - __ret; \ - } -#define API_STR2PTR(__string) \ - script_str2ptr (weechat_tcl_plugin, TCL_CURRENT_SCRIPT_NAME, \ - tcl_function_name, __string) -#define API_RETURN_OK \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - Tcl_SetIntObj (objp, 1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - Tcl_SetIntObj (objp, 1); \ - return TCL_OK; \ - } -#define API_RETURN_ERROR \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - Tcl_SetIntObj (objp, 0); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - Tcl_SetIntObj (objp, 0); \ - return TCL_ERROR; \ - } -#define API_RETURN_EMPTY \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - Tcl_SetStringObj (objp, "", -1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - Tcl_SetStringObj (objp, "", -1); \ - return TCL_OK; \ - } -#define API_RETURN_STRING(__string) \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - if (__string) \ - { \ - Tcl_SetStringObj (objp, __string, -1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - return TCL_OK; \ - } \ - Tcl_SetStringObj (objp, "", -1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - { \ - if (__string) \ - { \ - Tcl_SetStringObj (objp, __string, -1); \ - return TCL_OK; \ - } \ - Tcl_SetStringObj (objp, "", -1); \ - } \ - return TCL_OK; \ - } -#define API_RETURN_STRING_FREE(__string) \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - if (__string) \ - { \ - Tcl_SetStringObj (objp, __string, -1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - free (__string); \ - return TCL_OK; \ - } \ - Tcl_SetStringObj (objp, "", -1); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - { \ - if (__string) \ - { \ - Tcl_SetStringObj (objp, __string, -1); \ - free (__string); \ - return TCL_OK; \ - } \ - Tcl_SetStringObj (objp, "", -1); \ - } \ - return TCL_OK; \ - } -#define API_RETURN_INT(__int) \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - Tcl_SetIntObj (objp, __int); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - Tcl_SetIntObj (objp, __int); \ - return TCL_OK; \ - } -#define API_RETURN_LONG(__long) \ - { \ - objp = Tcl_GetObjResult (interp); \ - if (Tcl_IsShared (objp)) \ - { \ - objp = Tcl_DuplicateObj (objp); \ - Tcl_IncrRefCount (objp); \ - Tcl_SetLongObj (objp, __long); \ - Tcl_SetObjResult (interp, objp); \ - Tcl_DecrRefCount (objp); \ - } \ - else \ - Tcl_SetLongObj (objp, __long); \ - return TCL_OK; \ - } -#define API_RETURN_OBJ(__obj) \ - { \ - Tcl_SetObjResult (interp, __obj); \ - return TCL_OK; \ - } - -#define API_DEF_FUNC(__name) \ - Tcl_CreateObjCommand (interp, "weechat::" #__name, \ - weechat_tcl_api_##__name, \ - (ClientData) NULL, \ - (Tcl_CmdDeleteProc*)NULL); - - -/* - * weechat_tcl_api_register: startup function for all WeeChat Tcl scripts - */ - -static int -weechat_tcl_api_register (ClientData clientData, Tcl_Interp *interp, int objc, - Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *name, *author, *version, *license, *description, *shutdown_func; - char *charset; - int i; - - API_FUNC(0, "register", API_RETURN_ERROR); - if (tcl_registered_script) - { - /* script already registered */ - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" already " - "registered (register ignored)"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, - tcl_registered_script->name); - API_RETURN_ERROR; - } - tcl_current_script = NULL; - tcl_registered_script = NULL; - - if (objc < 8) - API_WRONG_ARGS(API_RETURN_ERROR); - - name = Tcl_GetStringFromObj (objv[1], &i); - author = Tcl_GetStringFromObj (objv[2], &i); - version = Tcl_GetStringFromObj (objv[3], &i); - license = Tcl_GetStringFromObj (objv[4], &i); - description = Tcl_GetStringFromObj (objv[5], &i); - shutdown_func = Tcl_GetStringFromObj (objv[6], &i); - charset = Tcl_GetStringFromObj (objv[7], &i); - - if (script_search (weechat_tcl_plugin, tcl_scripts, name)) - { - /* another script already exists with same name */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to register script " - "\"%s\" (another script already " - "exists with this name)"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, name); - API_RETURN_ERROR; - } - - /* register script */ - tcl_current_script = script_add (weechat_tcl_plugin, - &tcl_scripts, &last_tcl_script, - (tcl_current_script_filename) ? - tcl_current_script_filename : "", - name, author, version, license, - description, shutdown_func, charset); - if (tcl_current_script) - { - tcl_registered_script = tcl_current_script; - if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - TCL_PLUGIN_NAME, name, version, description); - } - tcl_current_script->interpreter = (void *)interp; - } - else - { - API_RETURN_ERROR; - } - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_plugin_get_name: get name of plugin (return "core" for - * WeeChat core) - */ - -static int -weechat_tcl_api_plugin_get_name (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *plugin; - const char *result; - int i; - - API_FUNC(1, "plugin_get_name", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - plugin = Tcl_GetStringFromObj (objv[1], &i); - - result = weechat_plugin_get_name (API_STR2PTR(plugin)); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_charset_set: set script charset - */ - -static int -weechat_tcl_api_charset_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "charset_set", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_charset_set (tcl_current_script, - Tcl_GetStringFromObj (objv[1], &i)); /* charset */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_iconv_to_internal: convert string to internal WeeChat - * charset - */ - -static int -weechat_tcl_api_iconv_to_internal (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *charset, *string; - int i; - - API_FUNC(1, "iconv_to_internal", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = Tcl_GetStringFromObj (objv[1], &i); - string = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_iconv_to_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_iconv_from_internal: convert string from WeeChat inernal - * charset to another one - */ - -static int -weechat_tcl_api_iconv_from_internal (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *charset, *string; - int i; - - API_FUNC(1, "iconv_from_internal", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - charset = Tcl_GetStringFromObj (objv[1], &i); - string = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_iconv_from_internal (charset, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_gettext: get translated string - */ - -static int -weechat_tcl_api_gettext (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "gettext", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_gettext (Tcl_GetStringFromObj (objv[1], &i)); /* string */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_ngettext: get translated string with plural form - */ - -static int -weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *single, *plural; - const char *result; - int i, count; - - API_FUNC(1, "ngettext", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - single = Tcl_GetStringFromObj (objv[1], &i); - plural = Tcl_GetStringFromObj (objv[2], &i); - - if (Tcl_GetIntFromObj (interp, objv[3], &count) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_ngettext (single, plural, count); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_string_match: return 1 if string matches a mask - * mask can begin or end with "*", no other "*" - * are allowed inside mask - */ - -static int -weechat_tcl_api_string_match (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *string, *mask; - int case_sensitive, result, i; - - API_FUNC(1, "string_match", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = Tcl_GetStringFromObj (objv[1], &i); - mask = Tcl_GetStringFromObj (objv[2], &i); - - if (Tcl_GetIntFromObj (interp, objv[3], &case_sensitive) != TCL_OK) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_string_match (string, mask, case_sensitive); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_string_has_highlight: return 1 if string contains a - * highlight (using list of words to - * highlight) - * return 0 if no highlight is found in - * string - */ - -static int -weechat_tcl_api_string_has_highlight (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *string, *highlight_words; - int result, i; - - API_FUNC(1, "string_has_highlight", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = Tcl_GetStringFromObj (objv[1], &i); - highlight_words = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_string_has_highlight (string, highlight_words); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_string_has_highlight_regex: return 1 if string contains a - * highlight (using a regular - * expression) - * return 0 if no highlight is - * found in string - */ - -static int -weechat_tcl_api_string_has_highlight_regex (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *string, *regex; - int result, i; - - API_FUNC(1, "string_has_highlight_regex", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - string = Tcl_GetStringFromObj (objv[1], &i); - regex = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_string_has_highlight_regex (string, regex); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_string_mask_to_regex: convert a mask (string with only - * "*" as wildcard) to a regex, paying - * attention to special chars in a - * regex - */ - -static int -weechat_tcl_api_string_mask_to_regex (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *mask; - int i; - - API_FUNC(1, "string_mask_to_regex", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - mask = Tcl_GetStringFromObj (objv[1], &i); - - result = weechat_string_mask_to_regex (mask); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_string_remove_color: remove WeeChat color codes from string - */ - -static int -weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *replacement, *string; - int i; - - API_FUNC(1, "string_remove_color", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - string = Tcl_GetStringFromObj (objv[1], &i); - replacement = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_string_remove_color (string, replacement); - - API_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; - - API_FUNC(1, "string_is_command_char", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_string_is_command_char (Tcl_GetStringFromObj (objv[1], &i)); /* string */ - - API_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; - - API_FUNC(1, "string_input_for_buffer", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_string_input_for_buffer (Tcl_GetStringFromObj (objv[1], &i)); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_mkdir_home: create a directory in WeeChat home - */ - -static int -weechat_tcl_api_mkdir_home (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i, mode; - - API_FUNC(1, "mkdir_home", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (weechat_mkdir_home (Tcl_GetStringFromObj (objv[1], &i), /* directory */ - mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_tcl_api_mkdir: create a directory - */ - -static int -weechat_tcl_api_mkdir (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i, mode; - - API_FUNC(1, "mkdir", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (weechat_mkdir (Tcl_GetStringFromObj (objv[1], &i), /* directory */ - mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_tcl_api_mkdir_parents: create a directory and make parent - * directories as needed - */ - -static int -weechat_tcl_api_mkdir_parents (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i, mode; - - API_FUNC(1, "mkdir_parents", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (weechat_mkdir_parents (Tcl_GetStringFromObj (objv[1], &i), /* directory */ - mode)) - API_RETURN_OK; - - API_RETURN_ERROR; -} - -/* - * weechat_tcl_api_list_new: create a new list - */ - -static int -weechat_tcl_api_list_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "list_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_add: add a string to list - */ - -static int -weechat_tcl_api_list_add (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *weelist, *data, *where, *user_data; - int i; - - - API_FUNC(1, "list_add", API_RETURN_EMPTY); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - data = Tcl_GetStringFromObj (objv[2], &i); - where = Tcl_GetStringFromObj (objv[3], &i); - user_data = Tcl_GetStringFromObj (objv[4], &i); - - result = script_ptr2str (weechat_list_add (API_STR2PTR(weelist), - data, - where, - API_STR2PTR(user_data))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_search: search a string in list - */ - -static int -weechat_tcl_api_list_search (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *weelist, *data; - int i; - - API_FUNC(1, "list_search", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - data = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_list_search (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_search_pos: search position of a string in list - */ - -static int -weechat_tcl_api_list_search_pos (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *weelist, *data; - int i, pos; - - API_FUNC(1, "list_search_pos", API_RETURN_INT(-1)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - data = Tcl_GetStringFromObj (objv[2], &i); - - pos = weechat_list_search_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_tcl_api_list_casesearch: search a string in list (ignore case) - */ - -static int -weechat_tcl_api_list_casesearch (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *weelist, *data; - int i; - - API_FUNC(1, "list_casesearch", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - data = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_list_casesearch (API_STR2PTR(weelist), - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_casesearch_pos: search position of a string in list - * (ignore case) - */ - -static int -weechat_tcl_api_list_casesearch_pos (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *weelist, *data; - int i, pos; - - API_FUNC(1, "list_casesearch_pos", API_RETURN_INT(-1)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - data = Tcl_GetStringFromObj (objv[2], &i); - - pos = weechat_list_casesearch_pos (API_STR2PTR(weelist), data); - - API_RETURN_INT(pos); -} - -/* - * weechat_tcl_api_list_get: get item by position - */ - -static int -weechat_tcl_api_list_get (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i, position; - - API_FUNC(1, "list_get", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (Tcl_GetIntFromObj (interp, objv[2], &position) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_get (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* weelist */ - position)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_set: set new value for item - */ - -static int -weechat_tcl_api_list_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *item, *new_value; - int i; - - API_FUNC(1, "list_set", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - item = Tcl_GetStringFromObj (objv[1], &i); - new_value = Tcl_GetStringFromObj (objv[2], &i); - - weechat_list_set (API_STR2PTR(item), new_value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_list_next: get next item - */ - -static int -weechat_tcl_api_list_next (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "list_next", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_next (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)))); /* item */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_prev: get previous item - */ - -static int -weechat_tcl_api_list_prev (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "list_prev", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_list_prev (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)))); /* item */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_list_string: get string value of item - */ - -static int -weechat_tcl_api_list_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "list_string", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_list_string (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* item */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_list_size: get number of elements in list - */ - -static int -weechat_tcl_api_list_size (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int size; - int i; - - API_FUNC(1, "list_size", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - size = weechat_list_size (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* weelist */ - - API_RETURN_INT(size); -} - -/* - * weechat_tcl_api_list_remove: remove item from list - */ - -static int -weechat_tcl_api_list_remove (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *weelist, *item; - int i; - - API_FUNC(1, "list_remove", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - weelist = Tcl_GetStringFromObj (objv[1], &i); - item = Tcl_GetStringFromObj (objv[2], &i); - - weechat_list_remove (API_STR2PTR(weelist), - API_STR2PTR(item)); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_list_remove_all: remove all items from list - */ - -static int -weechat_tcl_api_list_remove_all (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - (void) clientData; - - API_FUNC(1, "list_remove_all", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_remove_all (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* weelist */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_list_free: free list - */ - -static int -weechat_tcl_api_list_free (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "list_free", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_list_free (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* weelist */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_reload_cb: callback for config reload - */ - -int -weechat_tcl_api_config_reload_cb (void *data, - struct t_config_file *config_file) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; -} - -/* - * weechat_tcl_api_config_new: create a new configuration file - */ - -static int -weechat_tcl_api_config_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name, *function, *data; - int i; - - API_FUNC(1, "config_new", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_config_new (weechat_tcl_plugin, - tcl_current_script, - name, - &weechat_tcl_api_config_reload_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_config_section_read_cb: callback for reading option in - * section - */ - -int -weechat_tcl_api_config_section_read_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_tcl_api_config_section_write_cb: callback for writing section - */ - -int -weechat_tcl_api_config_section_write_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_tcl_api_config_section_write_default_cb: callback for writing - * default values for section - */ - -int -weechat_tcl_api_config_section_write_default_cb (void *data, - struct t_config_file *config_file, - const char *section_name) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = (section_name) ? (char *)section_name : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_WRITE_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_CONFIG_WRITE_ERROR; -} - -/* - * weechat_tcl_api_config_section_create_option_cb: callback to create an - * option - */ - -int -weechat_tcl_api_config_section_create_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = (option_name) ? (char *)option_name : empty_arg; - func_argv[4] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_SET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_SET_ERROR; -} - -/* - * weechat_tcl_api_config_section_delete_option_cb: callback to delete an - * option - */ - -int -weechat_tcl_api_config_section_delete_option_cb (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (config_file); - func_argv[2] = script_ptr2str (section); - func_argv[3] = script_ptr2str (option); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_CONFIG_OPTION_UNSET_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_CONFIG_OPTION_UNSET_ERROR; -} - -/* - * weechat_tcl_api_config_new_section: create a new section in configuration - * file - */ - -static int -weechat_tcl_api_config_new_section (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *cfg_file, *name, *function_read, *data_read; - char *function_write, *data_write, *function_write_default; - char *data_write_default, *function_create_option, *data_create_option; - char *function_delete_option, *data_delete_option; - int i, can_add, can_delete; - - /* make C compiler happy */ - (void) clientData; - - API_FUNC(1, "config_new_section", API_RETURN_EMPTY); - if (objc < 15) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[3], &can_add) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[4], &can_delete) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - cfg_file = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - function_read = Tcl_GetStringFromObj (objv[5], &i); - data_read = Tcl_GetStringFromObj (objv[6], &i); - function_write = Tcl_GetStringFromObj (objv[7], &i); - data_write = Tcl_GetStringFromObj (objv[8], &i); - function_write_default = Tcl_GetStringFromObj (objv[9], &i); - data_write_default = Tcl_GetStringFromObj (objv[10], &i); - function_create_option = Tcl_GetStringFromObj (objv[11], &i); - data_create_option = Tcl_GetStringFromObj (objv[12], &i); - function_delete_option = Tcl_GetStringFromObj (objv[13], &i); - data_delete_option = Tcl_GetStringFromObj (objv[14], &i); - - result = script_ptr2str (script_api_config_new_section (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(cfg_file), - name, - can_add, /* user_can_add_options */ - can_delete, /* user_can_delete_options */ - &weechat_tcl_api_config_section_read_cb, - function_read, - data_read, - &weechat_tcl_api_config_section_write_cb, - function_write, - data_write, - &weechat_tcl_api_config_section_write_default_cb, - function_write_default, - data_write_default, - &weechat_tcl_api_config_section_create_option_cb, - function_create_option, - data_create_option, - &weechat_tcl_api_config_section_delete_option_cb, - function_delete_option, - data_delete_option)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_config_search_section: search section in configuration file - */ - -static int -weechat_tcl_api_config_search_section (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *config_file, *section_name; - int i; - - API_FUNC(1, "config_search_section", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = Tcl_GetStringFromObj (objv[1], &i); - section_name = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_config_search_section (API_STR2PTR(config_file), - section_name)); - - API_RETURN_STRING_FREE(result); -} - - -/* - * weechat_tcl_api_config_option_check_value_cb: callback for checking new - * value for option - */ - -int -weechat_tcl_api_config_option_check_value_cb (void *data, - struct t_config_option *option, - const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = 0; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return 0; -} - -/* - * weechat_tcl_api_config_option_change_cb: callback for option changed - */ - -void -weechat_tcl_api_config_option_change_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_tcl_api_config_option_delete_cb: callback when option is deleted - */ - -void -weechat_tcl_api_config_option_delete_cb (void *data, - struct t_config_option *option) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (option); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - - if (rc) - free (rc); - } -} - -/* - * weechat_tcl_api_config_new_option: create a new option in section - */ - -static int -weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *config_file, *section, *name, *type; - char *description, *string_values, *default_value, *value; - char *function_check_value, *data_check_value, *function_change; - char *data_change, *function_delete, *data_delete; - int i, min, max, null_value_allowed; - - API_FUNC(1, "config_new_option", API_RETURN_EMPTY); - if (objc < 18) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[7], &min) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[8], &max) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[11], &null_value_allowed) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = Tcl_GetStringFromObj (objv[1], &i); - section = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - type = Tcl_GetStringFromObj (objv[4], &i); - description = Tcl_GetStringFromObj (objv[5], &i); - string_values = Tcl_GetStringFromObj (objv[6], &i); - default_value = Tcl_GetStringFromObj (objv[9], &i); - value = Tcl_GetStringFromObj (objv[10], &i); - function_check_value = Tcl_GetStringFromObj (objv[12], &i); - data_check_value = Tcl_GetStringFromObj (objv[13], &i); - function_change = Tcl_GetStringFromObj (objv[14], &i); - data_change = Tcl_GetStringFromObj (objv[15], &i); - function_delete = Tcl_GetStringFromObj (objv[16], &i); - data_delete = Tcl_GetStringFromObj (objv[17], &i); - - result = script_ptr2str (script_api_config_new_option (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(config_file), - API_STR2PTR(section), - name, - type, - description, - string_values, - min, - max, - default_value, - value, - null_value_allowed, - &weechat_tcl_api_config_option_check_value_cb, - function_check_value, - data_check_value, - &weechat_tcl_api_config_option_change_cb, - function_change, - data_change, - &weechat_tcl_api_config_option_delete_cb, - function_delete, - data_delete)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_config_search_option: search option in configuration file or - * section - */ - -static int -weechat_tcl_api_config_search_option (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *config_file, *section, *option_name; - int i; - - API_FUNC(1, "config_search_option", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - config_file = Tcl_GetStringFromObj (objv[1], &i); - section = Tcl_GetStringFromObj (objv[2], &i); - option_name = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_config_search_option (API_STR2PTR(config_file), - API_STR2PTR(section), - option_name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_config_string_to_boolean: return boolean value of a string - */ - -static int -weechat_tcl_api_config_string_to_boolean (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_string_to_boolean", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_string_to_boolean (Tcl_GetStringFromObj (objv[1], &i)); /* text */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_option_reset: reset an option with default value - */ - -static int -weechat_tcl_api_config_option_reset (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - char *option; - int i, run_callback; - - API_FUNC(1, "config_option_reset", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - if (Tcl_GetIntFromObj (interp, objv[2], &run_callback) != TCL_OK) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = Tcl_GetStringFromObj (objv[1], &i); - - rc = weechat_config_option_reset (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_option_set: set new value for option - */ - -static int -weechat_tcl_api_config_option_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - char *option, *new_value; - int i, run_callback; - - API_FUNC(1, "config_option_set", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - if (Tcl_GetIntFromObj (interp, objv[3], &run_callback) != TCL_OK) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = Tcl_GetStringFromObj (objv[1], &i); - new_value = Tcl_GetStringFromObj (objv[2], &i); - - rc = weechat_config_option_set (API_STR2PTR(option), - new_value, - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_option_set_null: set null (undefined)value for option - */ - -static int -weechat_tcl_api_config_option_set_null (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - char *option; - int i, run_callback; - - API_FUNC(1, "config_option_set_null", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - if (Tcl_GetIntFromObj (interp, objv[2], &run_callback) != TCL_OK) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = Tcl_GetStringFromObj (objv[1], &i); - - rc = weechat_config_option_set_null (API_STR2PTR(option), - run_callback); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_option_unset: unset an option - */ - -static int -weechat_tcl_api_config_option_unset (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - char *option; - int i; - - API_FUNC(1, "config_option_unset", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = Tcl_GetStringFromObj (objv[1], &i); - - rc = weechat_config_option_unset (API_STR2PTR(option)); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_option_rename: rename an option - */ - -static int -weechat_tcl_api_config_option_rename (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *option, *new_name; - int i; - - API_FUNC(1, "config_option_rename", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = Tcl_GetStringFromObj (objv[1], &i); - new_name = Tcl_GetStringFromObj (objv[2], &i); - - weechat_config_option_rename (API_STR2PTR(option), - new_name); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_option_is_null: return 1 if value of option is null - */ - -static int -weechat_tcl_api_config_option_is_null (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_option_is_null", API_RETURN_INT(1)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(1)); - - result = weechat_config_option_is_null (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_option_default_is_null: return 1 if default value of - * option is null - */ - -static int -weechat_tcl_api_config_option_default_is_null (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_option_default_is_null", API_RETURN_INT(1)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(1)); - - result = weechat_config_option_default_is_null (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_boolean: return boolean value of option - */ - -static int -weechat_tcl_api_config_boolean (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_boolean", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_boolean (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_boolean_default: return default boolean value of option - */ - -static int -weechat_tcl_api_config_boolean_default (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_boolean_default", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_boolean_default (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_integer: return integer value of option - */ - -static int -weechat_tcl_api_config_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_integer", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_integer (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_integer_default: return default integer value of option - */ - -static int -weechat_tcl_api_config_integer_default (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "config_integer_default", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_integer_default (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_config_string: return string value of option - */ - -static int -weechat_tcl_api_config_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "config_string", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_config_string_default: return default string value of option - */ - -static int -weechat_tcl_api_config_string_default (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "config_string_default", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_config_string_default (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_config_color: return color value of option - */ - -static int -weechat_tcl_api_config_color (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "config_color", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_config_color_default: return default color value of option - */ - -static int -weechat_tcl_api_config_color_default (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "config_color_default", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_config_color_default (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_config_write_option: write an option in configuration file - */ - -static int -weechat_tcl_api_config_write_option (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *config_file, *option; - int i; - - API_FUNC(1, "config_write_option", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = Tcl_GetStringFromObj (objv[1], &i); - option = Tcl_GetStringFromObj (objv[2], &i); - - weechat_config_write_option (API_STR2PTR(config_file), - API_STR2PTR(option)); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_write_line: write a line in configuration file - */ - -static int -weechat_tcl_api_config_write_line (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *config_file, *option_name, *value; - int i; - - API_FUNC(1, "config_write_line", API_RETURN_ERROR); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - config_file = Tcl_GetStringFromObj (objv[1], &i); - option_name = Tcl_GetStringFromObj (objv[2], &i); - value = Tcl_GetStringFromObj (objv[3], &i); - - weechat_config_write_line (API_STR2PTR(config_file), option_name, - "%s", value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_write: write configuration file - */ - -static int -weechat_tcl_api_config_write (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - int i; - - API_FUNC(1, "config_write", API_RETURN_INT(-1)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_write (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_read: read configuration file - */ - -static int -weechat_tcl_api_config_read (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - int i; - - API_FUNC(1, "config_read", API_RETURN_INT(-1)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_read (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_reload: reload configuration file - */ - -static int -weechat_tcl_api_config_reload (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int rc; - int i; - - API_FUNC(1, "config_reload", API_RETURN_INT(-1)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - rc = weechat_config_reload (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* config_file */ - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_option_free: free an option in configuration file - */ - -static int -weechat_tcl_api_config_option_free (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "config_option_free", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_option_free (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_section_free_options: free all options of a section - * in configuration file - */ - -static int -weechat_tcl_api_config_section_free_options (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "config_section_free_options", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free_options (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* section */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_section_free: free section in configuration file - */ - -static int -weechat_tcl_api_config_section_free (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "config_section_free", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_section_free (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* section */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_free: free configuration file - */ - -static int -weechat_tcl_api_config_free (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "config_free", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_config_free (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* config_file */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_get: get config option - */ - -static int -weechat_tcl_api_config_get (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "config_get", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_config_get (Tcl_GetStringFromObj (objv[1], &i))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_config_get_plugin: get value of a plugin option - */ - -static int -weechat_tcl_api_config_get_plugin (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "config_get_plugin", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_api_config_get_plugin (weechat_tcl_plugin, - tcl_current_script, - Tcl_GetStringFromObj (objv[1], &i)); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_config_is_set_plugin: check if a plugin option is set - */ - -static int -weechat_tcl_api_config_is_set_plugin (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *option; - int i, rc; - - API_FUNC(1, "config_is_set_plugin", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - option = Tcl_GetStringFromObj (objv[1], &i); - - rc = script_api_config_is_set_plugin (weechat_tcl_plugin, - tcl_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_set_plugin: set value of a plugin option - */ - -static int -weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *option, *value; - int i, rc; - - API_FUNC(1, "config_set_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR)); - - option = Tcl_GetStringFromObj (objv[1], &i); - value = Tcl_GetStringFromObj (objv[2], &i); - - rc = script_api_config_set_plugin (weechat_tcl_plugin, - tcl_current_script, - option, - value); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_config_set_desc_plugin: set description of a plugin option - */ - -static int -weechat_tcl_api_config_set_desc_plugin (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *option, *description; - int i; - - API_FUNC(1, "config_set_desc_plugin", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - option = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - - script_api_config_set_desc_plugin (weechat_tcl_plugin, - tcl_current_script, - option, - description); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_config_set_plugin: unset plugin option - */ - -static int -weechat_tcl_api_config_unset_plugin (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *option; - int i, rc; - - API_FUNC(1, "config_unset_plugin", API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR)); - - option = Tcl_GetStringFromObj (objv[1], &i); - - rc = script_api_config_unset_plugin (weechat_tcl_plugin, - tcl_current_script, - option); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_key_bind: bind key(s) - */ - -static int -weechat_tcl_api_key_bind (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *context; - struct t_hashtable *hashtable; - int i, num_keys; - - API_FUNC(1, "key_bind", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = Tcl_GetStringFromObj (objv[1], &i); - hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2], - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - num_keys = weechat_key_bind (context, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_tcl_api_key_unbind: unbind key(s) - */ - -static int -weechat_tcl_api_key_unbind (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *context, *key; - int i, num_keys; - - API_FUNC(1, "key_unbind", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - context = Tcl_GetStringFromObj (objv[1], &i); - key = Tcl_GetStringFromObj (objv[2], &i); - - num_keys = weechat_key_unbind (context, key); - - API_RETURN_INT(num_keys); -} - -/* - * weechat_tcl_api_prefix: get a prefix, used for display - */ - -static int -weechat_tcl_api_prefix (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(0, "prefix", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_prefix (Tcl_GetStringFromObj (objv[1], &i)); /* prefix */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_color: get a color code, used for display - */ - -static int -weechat_tcl_api_color (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(0, "color", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_color (Tcl_GetStringFromObj (objv[1], &i)); /* color */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_print: print message in a buffer - */ - -static int -weechat_tcl_api_print (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *message; - int i; - - API_FUNC(0, "print", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - message = Tcl_GetStringFromObj (objv[2], &i); - - script_api_printf (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(buffer), - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_print_date_tags: print message in a buffer with optional - * date and tags - */ - -static int -weechat_tcl_api_print_date_tags (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *tags, *message; - int i, tdate; - - API_FUNC(1, "print_date_tags", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &tdate) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - tags = Tcl_GetStringFromObj (objv[3], &i); - message = Tcl_GetStringFromObj (objv[4], &i); - - script_api_printf_date_tags (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(buffer), - tdate, - tags, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_print_y: print message in a buffer with free content - */ - -static int -weechat_tcl_api_print_y (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *message; - int i, y; - - API_FUNC(1, "print_y", API_RETURN_ERROR); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &y) != TCL_OK) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - message = Tcl_GetStringFromObj (objv[3], &i); - - script_api_printf_y (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(buffer), - y, - "%s", message); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_log_print: print message in WeeChat log file - */ - -static int -weechat_tcl_api_log_print (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - /* make C compiler happy */ - (void) clientData; - - API_FUNC(1, "log_print", API_RETURN_ERROR); - - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_log_printf (weechat_tcl_plugin, - tcl_current_script, - "%s", Tcl_GetStringFromObj (objv[1], &i)); /* message */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_hook_command_cb: callback for command hooked - */ - -int -weechat_tcl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - /* make C compiler happy */ - (void) argv; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_command: hook a command - */ - -static int -weechat_tcl_api_hook_command (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *command, *description, *args, *args_description; - char *completion, *function, *data; - int i; - - API_FUNC(1, "hook_command", API_RETURN_EMPTY); - if (objc < 8) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - args = Tcl_GetStringFromObj (objv[3], &i); - args_description = Tcl_GetStringFromObj (objv[4], &i); - completion = Tcl_GetStringFromObj (objv[5], &i); - function = Tcl_GetStringFromObj (objv[6], &i); - data = Tcl_GetStringFromObj (objv[7], &i); - - result = script_ptr2str (script_api_hook_command (weechat_tcl_plugin, - tcl_current_script, - command, - description, - args, - args_description, - completion, - &weechat_tcl_api_hook_command_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_command_run_cb: callback for command_run hooked - */ - -int -weechat_tcl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, - const char *command) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (command) ? (char *)command : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_command_run: hook a command_run - */ - -static int -weechat_tcl_api_hook_command_run (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *command, *function, *data; - int i; - - API_FUNC(1, "hook_command_run", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_command_run (weechat_tcl_plugin, - tcl_current_script, - command, - &weechat_tcl_api_hook_command_run_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_timer_cb: callback for timer hooked - */ - -int -weechat_tcl_api_hook_timer_cb (void *data, int remaining_calls) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_remaining_calls[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_remaining_calls, sizeof (str_remaining_calls), - "%d", remaining_calls); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_remaining_calls; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_timer: hook a timer - */ - -static int -weechat_tcl_api_hook_timer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i, interval, align_second, max_calls; - - API_FUNC(1, "hook_timer", API_RETURN_EMPTY); - if (objc < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[1], &interval) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[2], &align_second) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[3], &max_calls) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - - result = script_ptr2str (script_api_hook_timer (weechat_tcl_plugin, - tcl_current_script, - interval, /* interval */ - align_second, /* align_second */ - max_calls, /* max_calls */ - &weechat_tcl_api_hook_timer_cb, - Tcl_GetStringFromObj (objv[4], &i), /* tcl function */ - Tcl_GetStringFromObj (objv[5], &i))); /* data */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_fd_cb: callback for fd hooked - */ - -int -weechat_tcl_api_hook_fd_cb (void *data, int fd) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char str_fd[32], empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_fd, sizeof (str_fd), "%d", fd); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_fd; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_fd: hook a fd - */ - -static int -weechat_tcl_api_hook_fd (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i, fd, read, write, exception; - - API_FUNC(1, "hook_fd", API_RETURN_EMPTY); - if (objc < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[1], &fd) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[2], &read) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[3], &write) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[4], &exception) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (script_api_hook_fd (weechat_tcl_plugin, - tcl_current_script, - fd, /* fd */ - read, /* read */ - write, /* write */ - exception, /* exception */ - &weechat_tcl_api_hook_fd_cb, - Tcl_GetStringFromObj (objv[5], &i), /* tcl function */ - Tcl_GetStringFromObj (objv[6], &i))); /* data */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_process_cb: callback for process hooked - */ - -int -weechat_tcl_api_hook_process_cb (void *data, - const char *command, int return_code, - const char *out, const char *err) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (command) ? (char *)command : empty_arg; - func_argv[2] = &return_code; - func_argv[3] = (out) ? (char *)out : empty_arg; - func_argv[4] = (err) ? (char *)err : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssiss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_process: hook a process - */ - -static int -weechat_tcl_api_hook_process (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *command, *function, *data, *result; - int i, timeout; - - API_FUNC(1, "hook_process", API_RETURN_EMPTY); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[2], &timeout) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[3], &i); - data = Tcl_GetStringFromObj (objv[4], &i); - - result = script_ptr2str (script_api_hook_process (weechat_tcl_plugin, - tcl_current_script, - command, - timeout, - &weechat_tcl_api_hook_process_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_process_hashtable: hook a process with options in - * a hashtable - */ - -static int -weechat_tcl_api_hook_process_hashtable (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *command, *function, *data, *result; - struct t_hashtable *options; - int i, timeout; - - API_FUNC(1, "hook_process_hashtable", API_RETURN_EMPTY); - if (objc < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[3], &timeout) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - command = Tcl_GetStringFromObj (objv[1], &i); - options = weechat_tcl_dict_to_hashtable (interp, objv[2], - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - function = Tcl_GetStringFromObj (objv[4], &i); - data = Tcl_GetStringFromObj (objv[5], &i); - - result = script_ptr2str (script_api_hook_process_hashtable (weechat_tcl_plugin, - tcl_current_script, - command, - options, - timeout, - &weechat_tcl_api_hook_process_cb, - function, - data)); - - if (options) - weechat_hashtable_free (options); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_connect_cb: callback for connect hooked - */ - -int -weechat_tcl_api_hook_connect_cb (void *data, int status, int gnutls_rc, - const char *error, const char *ip_address) -{ - struct t_script_callback *script_callback; - void *func_argv[5]; - char str_status[32], str_gnutls_rc[32]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_status, sizeof (str_status), "%d", status); - snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = str_status; - func_argv[2] = str_gnutls_rc; - func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg; - func_argv[4] = (error) ? (char *)error : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_connect: hook a connection - */ - -static int -weechat_tcl_api_hook_connect (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *proxy, *address, *local_hostname, *function, *data, *result; - int i, port, sock, ipv6; - - API_FUNC(1, "hook_connect", API_RETURN_EMPTY); - if (objc < 9) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if ((Tcl_GetIntFromObj (interp, objv[3], &port) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[4], &sock) != TCL_OK) - || (Tcl_GetIntFromObj (interp, objv[5], &ipv6) != TCL_OK)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - proxy = Tcl_GetStringFromObj (objv[1], &i); - address = Tcl_GetStringFromObj (objv[2], &i); - local_hostname = Tcl_GetStringFromObj (objv[6], &i); - function = Tcl_GetStringFromObj (objv[7], &i); - data = Tcl_GetStringFromObj (objv[8], &i); - - result = script_ptr2str (script_api_hook_connect (weechat_tcl_plugin, - tcl_current_script, - proxy, - address, - port, - sock, - ipv6, - NULL, /* gnutls session */ - NULL, /* gnutls callback */ - 0, /* gnutls DH key size */ - NULL, /* gnutls priorities */ - local_hostname, - &weechat_tcl_api_hook_connect_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_print_cb: callback for print hooked - */ - -int -weechat_tcl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, - int tags_count, const char **tags, - int displayed, int highlight, - const char *prefix, const char *message) -{ - struct t_script_callback *script_callback; - void *func_argv[8]; - char empty_arg[1] = { '\0' }; - static char timebuffer[64]; - int *rc, ret; - - /* make C compiler happy */ - (void) tags_count; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", (long int)date); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = timebuffer; - func_argv[3] = weechat_string_build_with_split_string (tags, ","); - if (!func_argv[3]) - func_argv[3] = strdup (""); - func_argv[4] = (displayed) ? strdup ("1") : strdup ("0"); - func_argv[5] = (highlight) ? strdup ("1") : strdup ("0"); - func_argv[6] = (prefix) ? (char *)prefix : empty_arg; - func_argv[7] = (message) ? (char *)message : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssssssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - if (func_argv[4]) - free (func_argv[4]); - if (func_argv[5]) - free (func_argv[5]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_print: hook a print - */ - -static int -weechat_tcl_api_hook_print (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *buffer, *tags, *message, *function, *data; - int i, strip_colors; - - API_FUNC(1, "hook_print", API_RETURN_EMPTY); - if (objc < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (Tcl_GetIntFromObj (interp, objv[4], &strip_colors) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - tags = Tcl_GetStringFromObj (objv[2], &i); - message = Tcl_GetStringFromObj (objv[3], &i); - function = Tcl_GetStringFromObj (objv[5], &i); - data = Tcl_GetStringFromObj (objv[6], &i); - - result = script_ptr2str (script_api_hook_print (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(buffer), - tags, - message, - strip_colors, /* strip_colors */ - &weechat_tcl_api_hook_print_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_signal_cb: callback for signal hooked - */ - -int -weechat_tcl_api_hook_signal_cb (void *data, const char *signal, const char *type_data, - void *signal_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - static char value_str[64]; - int *rc, ret, free_needed; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - free_needed = 0; - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - func_argv[2] = (signal_data) ? (char *)signal_data : empty_arg; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - snprintf (value_str, sizeof (value_str) - 1, - "%d", *((int *)signal_data)); - func_argv[2] = value_str; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - func_argv[2] = script_ptr2str (signal_data); - free_needed = 1; - } - else - func_argv[2] = empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (free_needed && func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_signal: hook a signal - */ - -static int -weechat_tcl_api_hook_signal (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *signal, *function, *data; - int i; - - API_FUNC(1, "hook_signal", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_signal (weechat_tcl_plugin, - tcl_current_script, - signal, - &weechat_tcl_api_hook_signal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_signal_send: send a signal - */ - -static int -weechat_tcl_api_hook_signal_send (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *signal, *type_data; - int number; - int i; - - API_FUNC(1, "hook_signal_send", API_RETURN_ERROR); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = Tcl_GetStringFromObj (objv[1], &i); - type_data = Tcl_GetStringFromObj (objv[2], &i); - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - weechat_hook_signal_send (signal, - type_data, - Tcl_GetStringFromObj (objv[3], &i)); /* signal_data */ - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - if (Tcl_GetIntFromObj (interp, objv[3], &number) != TCL_OK) - { - API_RETURN_ERROR; - } - weechat_hook_signal_send (signal, - type_data, - &number); /* signal_data */ - API_RETURN_OK; - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - weechat_hook_signal_send (signal, - type_data, - API_STR2PTR(Tcl_GetStringFromObj (objv[3], &i))); /* signal_data */ - API_RETURN_OK; - } - - API_RETURN_ERROR; -} - -/* - * weechat_tcl_api_hook_hsignal_cb: callback for hsignal hooked - */ - -int -weechat_tcl_api_hook_hsignal_cb (void *data, const char *signal, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (signal) ? (char *)signal : empty_arg; - func_argv[2] = hashtable; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssh", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_hsignal: hook a hsignal - */ - -static int -weechat_tcl_api_hook_hsignal (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *signal, *function, *data; - int i; - - API_FUNC(1, "hook_hsignal", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - signal = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_hsignal (weechat_tcl_plugin, - tcl_current_script, - signal, - &weechat_tcl_api_hook_hsignal_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_hsignal_send: send a hsignal - */ - -static int -weechat_tcl_api_hook_hsignal_send (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *signal; - struct t_hashtable *hashtable; - int i; - - API_FUNC(1, "hook_hsignal_send", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - signal = Tcl_GetStringFromObj (objv[1], &i); - hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2], - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - weechat_hook_hsignal_send (signal, hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_hook_config_cb: callback for config option hooked - */ - -int -weechat_tcl_api_hook_config_cb (void *data, const char *option, const char *value) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (option) ? (char *)option : empty_arg; - func_argv[2] = (value) ? (char *)value : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_config: hook a config option - */ - -static int -weechat_tcl_api_hook_config (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *option, *function, *data; - int i; - - API_FUNC(1, "hook_config", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - option = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_config (weechat_tcl_plugin, - tcl_current_script, - option, - &weechat_tcl_api_hook_config_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_completion_cb: callback for completion hooked - */ - -int -weechat_tcl_api_hook_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = script_ptr2str (buffer); - func_argv[3] = script_ptr2str (completion); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_hook_completion: hook a completion - */ - -static int -weechat_tcl_api_hook_completion (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *completion, *description, *function, *data; - int i; - - API_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - function = Tcl_GetStringFromObj (objv[3], &i); - data = Tcl_GetStringFromObj (objv[4], &i); - - result = script_ptr2str (script_api_hook_completion (weechat_tcl_plugin, - tcl_current_script, - completion, - description, - &weechat_tcl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_completion_list_add: add a word to list for a completion - */ - -static int -weechat_tcl_api_hook_completion_list_add (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *completion, *word, *where; - int i, nick_completion; - - API_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[3], &nick_completion) != TCL_OK) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = Tcl_GetStringFromObj (objv[1], &i); - word = Tcl_GetStringFromObj (objv[2], &i); - where = Tcl_GetStringFromObj (objv[4], &i); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, /* nick_completion */ - where); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_hook_modifier_cb: callback for modifier hooked - */ - -char * -weechat_tcl_api_hook_modifier_cb (void *data, const char *modifier, - const char *modifier_data, const char *string) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (modifier) ? (char *)modifier : empty_arg; - func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg; - func_argv[3] = (string) ? (char *)string : empty_arg; - - return (char *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - } - - return NULL; -} - -/* - * weechat_tcl_api_hook_modifier: hook a modifier - */ - -static int -weechat_tcl_api_hook_modifier (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *modifier, *function, *data; - int i; - - API_FUNC(1, "hook_modifier", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - modifier = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_modifier (weechat_tcl_plugin, - tcl_current_script, - modifier, - &weechat_tcl_api_hook_modifier_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_modifier_exec: execute a modifier hook - */ - -static int -weechat_tcl_api_hook_modifier_exec (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *modifier, *modifier_data, *string; - int i; - - API_FUNC(1, "hook_modifier_exec", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - modifier = Tcl_GetStringFromObj (objv[1], &i); - modifier_data = Tcl_GetStringFromObj (objv[2], &i); - string = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hook_modifier_exec (modifier, modifier_data, string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_info_cb: callback for info hooked - */ - -const char * -weechat_tcl_api_hook_info_cb (void *data, const char *info_name, - const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - - return (const char *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - } - - return NULL; -} - -/* - * weechat_tcl_api_hook_info: hook an info - */ - -static int -weechat_tcl_api_hook_info (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *info_name, *description, *args_description, *function, *data; - int i; - - API_FUNC(1, "hook_info", API_RETURN_EMPTY); - if (objc < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - args_description = Tcl_GetStringFromObj (objv[3], &i); - function = Tcl_GetStringFromObj (objv[4], &i); - data = Tcl_GetStringFromObj (objv[5], &i); - - result = script_ptr2str (script_api_hook_info (weechat_tcl_plugin, - tcl_current_script, - info_name, - description, - args_description, - &weechat_tcl_api_hook_info_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_info_hashtable_cb: callback for info_hashtable hooked - */ - -struct t_hashtable * -weechat_tcl_api_hook_info_hashtable_cb (void *data, const char *info_name, - struct t_hashtable *hashtable) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (info_name) ? (char *)info_name : empty_arg; - func_argv[2] = hashtable; - - return (struct t_hashtable *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "ssh", func_argv); - } - - return NULL; -} - -/* - * weechat_tcl_api_hook_info_hashtable: hook an info_hashtable - */ - -static int -weechat_tcl_api_hook_info_hashtable (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *info_name, *description, *args_description; - char *output_description, *function, *data; - int i; - - API_FUNC(1, "hook_info_hashtable", API_RETURN_EMPTY); - if (objc < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - info_name = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - args_description = Tcl_GetStringFromObj (objv[3], &i); - output_description = Tcl_GetStringFromObj (objv[4], &i); - function = Tcl_GetStringFromObj (objv[5], &i); - data = Tcl_GetStringFromObj (objv[6], &i); - - result = script_ptr2str (script_api_hook_info_hashtable (weechat_tcl_plugin, - tcl_current_script, - info_name, - description, - args_description, - output_description, - &weechat_tcl_api_hook_info_hashtable_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_infolist_cb: callback for infolist hooked - */ - -struct t_infolist * -weechat_tcl_api_hook_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - struct t_infolist *result; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = (infolist_name) ? (char *)infolist_name : empty_arg; - func_argv[2] = script_ptr2str (pointer); - func_argv[3] = (arguments) ? (char *)arguments : empty_arg; - - result = (struct t_infolist *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "ssss", func_argv); - - if (func_argv[2]) - free (func_argv[2]); - - return result; - } - - return NULL; -} - -/* - * weechat_tcl_api_hook_infolist: hook an infolist - */ - -static int -weechat_tcl_api_hook_infolist (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *infolist_name, *description, *pointer_description; - char *args_description, *function, *data; - int i; - - API_FUNC(1, "hook_infolist", API_RETURN_EMPTY); - if (objc < 7) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist_name = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - pointer_description = Tcl_GetStringFromObj (objv[3], &i); - args_description = Tcl_GetStringFromObj (objv[4], &i); - function = Tcl_GetStringFromObj (objv[5], &i); - data = Tcl_GetStringFromObj (objv[6], &i); - - result = script_ptr2str (script_api_hook_infolist (weechat_tcl_plugin, - tcl_current_script, - infolist_name, - description, - pointer_description, - args_description, - &weechat_tcl_api_hook_infolist_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hook_focus_cb: callback for focus hooked - */ - -struct t_hashtable * -weechat_tcl_api_hook_focus_cb (void *data, - struct t_hashtable *info) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = info; - - return (struct t_hashtable *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_HASHTABLE, - script_callback->function, - "sh", func_argv); - } - - return NULL; -} - -/* - * weechat_tcl_api_hook_focus: hook a focus - */ - -static int -weechat_tcl_api_hook_focus (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *area, *function, *data; - int i; - - API_FUNC(1, "hook_focus", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - area = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_hook_focus (weechat_tcl_plugin, - tcl_current_script, - area, - &weechat_tcl_api_hook_focus_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_unhook: unhook something - */ - -static int -weechat_tcl_api_unhook (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "unhook", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_unhook (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* hook */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_unhook_all: unhook all for script - */ - -static int -weechat_tcl_api_unhook_all (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "unhook_all", API_RETURN_ERROR); - - script_api_unhook_all (weechat_tcl_plugin, tcl_current_script); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_input_data_cb: callback for input data in a buffer - */ - -int -weechat_tcl_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer, - const char *input_data) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - func_argv[2] = (input_data) ? (char *)input_data : empty_arg; - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "sss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_buffer_close_cb: callback for buffer closed - */ - -int -weechat_tcl_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) -{ - struct t_script_callback *script_callback; - void *func_argv[2]; - char empty_arg[1] = { '\0' }; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (buffer); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ss", func_argv); - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_buffer_new: create a new buffer - */ - -static int -weechat_tcl_api_buffer_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name, *function_input, *data_input, *function_close; - char *data_close; - int i; - - API_FUNC(1, "buffer_new", API_RETURN_EMPTY); - if (objc < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - function_input = Tcl_GetStringFromObj (objv[2], &i); - data_input = Tcl_GetStringFromObj (objv[3], &i); - function_close = Tcl_GetStringFromObj (objv[4], &i); - data_close = Tcl_GetStringFromObj (objv[5], &i); - - result = script_ptr2str (script_api_buffer_new (weechat_tcl_plugin, - tcl_current_script, - name, - &weechat_tcl_api_buffer_input_data_cb, - function_input, - data_input, - &weechat_tcl_api_buffer_close_cb, - function_close, - data_close)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_buffer_search: search a buffer - */ - -static int -weechat_tcl_api_buffer_search (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *plugin, *name; - int i; - - API_FUNC(1, "buffer_search", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - plugin = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_buffer_search (plugin, name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_buffer_search_main: search main buffer (WeeChat core buffer) - */ - -static int -weechat_tcl_api_buffer_search_main (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "buffer_search_main", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_buffer_search_main ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_current_buffer: get current buffer - */ - -static int -weechat_tcl_api_current_buffer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "current_buffer", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_buffer ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_buffer_clear: clear a buffer - */ - -static int -weechat_tcl_api_buffer_clear (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "buffer_clear", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_clear (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_close: close a buffer - */ - -static int -weechat_tcl_api_buffer_close (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "buffer_close", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_buffer_close (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_merge: merge a buffer to another buffer - */ - -static int -weechat_tcl_api_buffer_merge (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "buffer_merge", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_merge (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* buffer */ - API_STR2PTR(Tcl_GetStringFromObj (objv[2], &i))); /* target_buffer */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_unmerge: unmerge a buffer from a group of merged - * buffers - */ - -static int -weechat_tcl_api_buffer_unmerge (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i, number; - - API_FUNC(1, "buffer_unmerge", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[2], &number) != TCL_OK) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_buffer_unmerge (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), - number); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_get_integer: get a buffer property as integer - */ - -static int -weechat_tcl_api_buffer_get_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *property; - int result; - int i; - - API_FUNC(1, "buffer_get_integer", API_RETURN_INT(-1)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_buffer_get_integer (API_STR2PTR(buffer), property); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_buffer_get_string: get a buffer property as string - */ - -static int -weechat_tcl_api_buffer_get_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *property; - const char *result; - int i; - - API_FUNC(1, "buffer_get_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_buffer_get_string (API_STR2PTR(buffer), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_buffer_get_pointer: get a buffer property as pointer - */ - -static int -weechat_tcl_api_buffer_get_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *property, *result; - int i; - - API_FUNC(1, "buffer_get_pointer", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_buffer_get_pointer (API_STR2PTR(buffer), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_buffer_set: set a buffer property - */ - -static int -weechat_tcl_api_buffer_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *property, *value; - int i; - - API_FUNC(1, "buffer_set", API_RETURN_ERROR); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - value = Tcl_GetStringFromObj (objv[3], &i); - - weechat_buffer_set (API_STR2PTR(buffer), property, value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_buffer_string_replace_local_var: replace local variables ($var) in a string, - * using value of local variables - */ - -static int -weechat_tcl_api_buffer_string_replace_local_var (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *string, *result; - int i; - - API_FUNC(1, "buffer_string_replace_local_var", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - string = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_buffer_string_replace_local_var (API_STR2PTR(buffer), string); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_buffer_match_list: return 1 if buffers matches list of buffers - */ - -static int -weechat_tcl_api_buffer_match_list (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *string; - int result; - int i; - - API_FUNC(1, "buffer_match_list", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - string = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_buffer_match_list (API_STR2PTR(buffer), string); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_current_window: get current window - */ - -static int -weechat_tcl_api_current_window (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "current_window", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_current_window ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_window_search_with_buffer: search a window with buffer - * pointer - */ - -static int -weechat_tcl_api_window_search_with_buffer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *result; - int i; - - API_FUNC(1, "window_search_with_buffer", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - - result = script_ptr2str (weechat_window_search_with_buffer (API_STR2PTR(buffer))); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_window_get_integer: get a window property as integer - */ - -static int -weechat_tcl_api_window_get_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *window, *property; - int result; - int i; - - API_FUNC(1, "window_get_integer", API_RETURN_INT(-1)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - window = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_window_get_integer (API_STR2PTR(window), property); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_window_get_string: get a window property as string - */ - -static int -weechat_tcl_api_window_get_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *window, *property; - const char *result; - int i; - - API_FUNC(1, "window_get_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_window_get_string (API_STR2PTR(window), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_window_get_pointer: get a window property as pointer - */ - -static int -weechat_tcl_api_window_get_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *window, *property, *result; - int i; - - API_FUNC(1, "window_get_pointer", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - window = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_window_get_pointer (API_STR2PTR(window), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_window_set_title: set window title - */ - -static int -weechat_tcl_api_window_set_title (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *title; - int i; - - API_FUNC(1, "window_set_title", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - title = Tcl_GetStringFromObj (objv[1], &i); - - weechat_window_set_title (title); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_nicklist_add_group: add a group in nicklist - */ - -static int -weechat_tcl_api_nicklist_add_group (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *buffer, *parent_group, *name, *color; - int i, visible; - - API_FUNC(1, "nicklist_add_group", API_RETURN_EMPTY); - if (objc < 6) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (Tcl_GetIntFromObj (interp, objv[5], &visible) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - parent_group = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - color = Tcl_GetStringFromObj (objv[4], &i); - - result = script_ptr2str (weechat_nicklist_add_group (API_STR2PTR(buffer), - API_STR2PTR(parent_group), - name, - color, - visible)); /* visible */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_search_group: search a group in nicklist - */ - -static int -weechat_tcl_api_nicklist_search_group (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *buffer, *from_group, *name; - int i; - - API_FUNC(1, "nicklist_search_group", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - from_group = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_nicklist_search_group (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_add_nick: add a nick in nicklist - */ - -static int -weechat_tcl_api_nicklist_add_nick (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *buffer, *group, *name, *color, *prefix, *prefix_color; - int i, visible; - - API_FUNC(1, "nicklist_add_nick", API_RETURN_EMPTY); - if (objc < 8) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (Tcl_GetIntFromObj (interp, objv[7], &visible) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - color = Tcl_GetStringFromObj (objv[4], &i); - prefix = Tcl_GetStringFromObj (objv[5], &i); - prefix_color = Tcl_GetStringFromObj (objv[6], &i); - - result = script_ptr2str (weechat_nicklist_add_nick (API_STR2PTR(buffer), - API_STR2PTR(group), - name, - color, - prefix, - prefix_color, - visible)); /* visible */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_search_nick: search a nick in nicklist - */ - -static int -weechat_tcl_api_nicklist_search_nick (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *buffer, *from_group, *name; - int i; - - API_FUNC(1, "nicklist_search_nick", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - from_group = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_nicklist_search_nick (API_STR2PTR(buffer), - API_STR2PTR(from_group), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_remove_group: remove a group from nicklist - */ - -static int -weechat_tcl_api_nicklist_remove_group (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *group; - int i; - - API_FUNC(1, "nicklist_remove_group", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - - weechat_nicklist_remove_group (API_STR2PTR(buffer), - API_STR2PTR(group)); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_nicklist_remove_nick: remove a nick from nicklist - */ - -static int -weechat_tcl_api_nicklist_remove_nick (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *nick; - int i; - - API_FUNC(1, "nicklist_remove_nick", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - nick = Tcl_GetStringFromObj (objv[2], &i); - - weechat_nicklist_remove_nick (API_STR2PTR(buffer), - API_STR2PTR(nick)); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_nicklist_remove_all: remove all groups/nicks from nicklist - */ - -static int -weechat_tcl_api_nicklist_remove_all (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "nicklist_remove_all", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_nicklist_remove_all (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* buffer */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_nicklist_group_get_integer: get a group property as integer - */ - -static int -weechat_tcl_api_nicklist_group_get_integer (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *group, *property; - int result; - int i; - - API_FUNC(1, "nicklist_group_get_integer", API_RETURN_INT(-1)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_nicklist_group_get_integer (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_nicklist_group_get_string: get a group property as string - */ - -static int -weechat_tcl_api_nicklist_group_get_string (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *group, *property; - const char *result; - int i; - - API_FUNC(1, "nicklist_group_get_string", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_nicklist_group_get_string (API_STR2PTR(buffer), - API_STR2PTR(group), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_nicklist_group_get_pointer: get a group property as pointer - */ - -static int -weechat_tcl_api_nicklist_group_get_pointer (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *group, *property, *result; - int i; - - API_FUNC(1, "nicklist_group_get_pointer", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_nicklist_group_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(group), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_group_set: set a group property - */ - -static int -weechat_tcl_api_nicklist_group_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *group, *property, *value; - int i; - - API_FUNC(1, "nicklist_group_set", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - group = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - value = Tcl_GetStringFromObj (objv[4], &i); - - weechat_nicklist_group_set (API_STR2PTR(buffer), - API_STR2PTR(group), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_nicklist_nick_get_integer: get a nick property as integer - */ - -static int -weechat_tcl_api_nicklist_nick_get_integer (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *nick, *property; - int result; - int i; - - API_FUNC(1, "nicklist_nick_get_integer", API_RETURN_INT(-1)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - nick = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_nicklist_nick_get_integer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_nicklist_nick_get_string: get a nick property as string - */ - -static int -weechat_tcl_api_nicklist_nick_get_string (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *nick, *property; - const char *result; - int i; - - API_FUNC(1, "nicklist_nick_get_string", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - nick = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_nicklist_nick_get_string (API_STR2PTR(buffer), - API_STR2PTR(nick), - property); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_nicklist_nick_get_pointer: get a nick property as pointer - */ - -static int -weechat_tcl_api_nicklist_nick_get_pointer (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *nick, *property, *result; - int i; - - API_FUNC(1, "nicklist_nick_get_pointer", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - nick = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_nicklist_nick_get_pointer (API_STR2PTR(buffer), - API_STR2PTR(nick), - property)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_nicklist_nick_set: set a nick property - */ - -static int -weechat_tcl_api_nicklist_nick_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *nick, *property, *value; - int i; - - API_FUNC(1, "nicklist_nick_set", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - nick = Tcl_GetStringFromObj (objv[2], &i); - property = Tcl_GetStringFromObj (objv[3], &i); - value = Tcl_GetStringFromObj (objv[4], &i); - - weechat_nicklist_nick_set (API_STR2PTR(buffer), - API_STR2PTR(nick), - property, - value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_bar_item_search: search a bar item - */ - -static int -weechat_tcl_api_bar_item_search (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "bar_item_search", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_item_search (Tcl_GetStringFromObj (objv[1], &i))); /* name */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_bar_item_build_cb: callback for building bar item - */ - -char * -weechat_tcl_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, - struct t_gui_window *window) -{ - struct t_script_callback *script_callback; - void *func_argv[3]; - char empty_arg[1] = { '\0' }, *ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (item); - func_argv[2] = script_ptr2str (window); - - ret = (char *)weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_STRING, - script_callback->function, - "sss", func_argv); - - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[2]) - free (func_argv[2]); - - return ret; - } - - return NULL; -} - -/* - * weechat_tcl_api_bar_item_new: add a new bar item - */ - -static int -weechat_tcl_api_bar_item_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name, *function, *data; - int i; - - API_FUNC(1, "bar_item_new", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (script_api_bar_item_new (weechat_tcl_plugin, - tcl_current_script, - name, - &weechat_tcl_api_bar_item_build_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_bar_item_update: update a bar item on screen - */ - -static int -weechat_tcl_api_bar_item_update (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "bar_item_update", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_item_update (Tcl_GetStringFromObj (objv[1], &i)); /* name */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_bar_item_remove: remove a bar item - */ - -static int -weechat_tcl_api_bar_item_remove (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "bar_item_remove", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - script_api_bar_item_remove (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* item */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_bar_search: search a bar - */ - -static int -weechat_tcl_api_bar_search (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "bar_search", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_bar_search (Tcl_GetStringFromObj (objv[1], &i))); /* name */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_bar_new: add a new bar - */ - -static int -weechat_tcl_api_bar_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name, *hidden, *priority, *type, *conditions, *position; - char *filling_top_bottom, *filling_left_right, *size, *size_max, *color_fg; - char *color_delim, *color_bg, *separator, *bar_items; - int i; - - API_FUNC(1, "bar_new", API_RETURN_EMPTY); - if (objc < 16) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - hidden = Tcl_GetStringFromObj (objv[2], &i); - priority = Tcl_GetStringFromObj (objv[3], &i); - type = Tcl_GetStringFromObj (objv[4], &i); - conditions = Tcl_GetStringFromObj (objv[5], &i); - position = Tcl_GetStringFromObj (objv[6], &i); - filling_top_bottom = Tcl_GetStringFromObj (objv[7], &i); - filling_left_right = Tcl_GetStringFromObj (objv[8], &i); - size = Tcl_GetStringFromObj (objv[9], &i); - size_max = Tcl_GetStringFromObj (objv[10], &i); - color_fg = Tcl_GetStringFromObj (objv[11], &i); - color_delim = Tcl_GetStringFromObj (objv[12], &i); - color_bg = Tcl_GetStringFromObj (objv[13], &i); - separator = Tcl_GetStringFromObj (objv[14], &i); - bar_items = Tcl_GetStringFromObj (objv[15], &i); - - result = script_ptr2str (weechat_bar_new (name, - hidden, - priority, - type, - conditions, - position, - filling_top_bottom, - filling_left_right, - size, - size_max, - color_fg, - color_delim, - color_bg, - separator, - bar_items)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_bar_set: set a bar property - */ - -static int -weechat_tcl_api_bar_set (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *bar, *property, *value; - int i; - - API_FUNC(1, "bar_set", API_RETURN_ERROR); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - bar = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - value = Tcl_GetStringFromObj (objv[3], &i); - - weechat_bar_set (API_STR2PTR(bar), property, value); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_bar_update: update a bar on screen - */ - -static int -weechat_tcl_api_bar_update (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "bar_update", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_update (Tcl_GetStringFromObj (objv[1], &i)); /* name */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_bar_remove: remove a bar - */ - -static int -weechat_tcl_api_bar_remove (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "bar_remove", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_bar_remove (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* bar */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_command: execute a command on a buffer - */ - -static int -weechat_tcl_api_command (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *buffer, *command; - int i; - - API_FUNC(1, "command", API_RETURN_ERROR); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_ERROR); - - buffer = Tcl_GetStringFromObj (objv[1], &i); - command = Tcl_GetStringFromObj (objv[2], &i); - - script_api_command (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(buffer), - command); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_info_get: get info (as string) - */ - -static int -weechat_tcl_api_info_get (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "info_get", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_info_get (Tcl_GetStringFromObj (objv[1], &i), - Tcl_GetStringFromObj (objv[2], &i)); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_info_get_hashtable: get info (as hashtable) - */ - -static int -weechat_tcl_api_info_get_hashtable (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp, *result_dict; - struct t_hashtable *hashtable, *result_hashtable; - int i; - - API_FUNC(1, "info_get_hashtable", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2], - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - - result_hashtable = weechat_info_get_hashtable (Tcl_GetStringFromObj (objv[1], &i), - hashtable); - result_dict = weechat_tcl_hashtable_to_dict (interp, result_hashtable); - - if (hashtable) - weechat_hashtable_free (hashtable); - if (result_hashtable) - weechat_hashtable_free (result_hashtable); - - API_RETURN_OBJ(result_dict); -} - -/* - * weechat_tcl_api_infolist_new: create a new infolist - */ - -static int -weechat_tcl_api_infolist_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - - /* make C compiler happy */ - (void) clientData; - (void) objc; - (void) objv; - - API_FUNC(1, "infolist_new", API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new ()); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_new_item: create new item in infolist - */ - -static int -weechat_tcl_api_infolist_new_item (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "infolist_new_item", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = script_ptr2str (weechat_infolist_new_item (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)))); /* infolist */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_new_var_integer: create new integer variable in - * infolist - */ - -static int -weechat_tcl_api_infolist_new_var_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i, value; - - API_FUNC(1, "infolist_new_var_integer", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - if (Tcl_GetIntFromObj (interp, objv[3], &value) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_integer (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* infolist */ - Tcl_GetStringFromObj (objv[2], &i), /* name */ - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_new_var_string: create new string variable in - * infolist - */ - -static int -weechat_tcl_api_infolist_new_var_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "infolist_new_var_string", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = script_ptr2str (weechat_infolist_new_var_string (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* infolist */ - Tcl_GetStringFromObj (objv[2], &i), /* name */ - Tcl_GetStringFromObj (objv[3], &i))); /* value */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_new_var_pointer: create new pointer variable in infolist - */ - -static int -weechat_tcl_api_infolist_new_var_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i; - - API_FUNC(1, "infolist_new_var_pointer", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = script_ptr2str (weechat_infolist_new_var_pointer (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* infolist */ - Tcl_GetStringFromObj (objv[2], &i), /* name */ - API_STR2PTR(Tcl_GetStringFromObj (objv[3], &i)))); /* value */ - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_new_var_time: create new time variable in infolist - */ - -static int -weechat_tcl_api_infolist_new_var_time (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result; - int i, value; - - API_FUNC(1, "infolist_new_var_time", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - if (Tcl_GetIntFromObj (interp, objv[3], &value) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_infolist_new_var_time (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i)), /* infolist */ - Tcl_GetStringFromObj (objv[2], &i), /* name */ - value)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_get: get list with infos - */ - -static int -weechat_tcl_api_infolist_get (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name, *pointer, *arguments; - int i; - - API_FUNC(1, "infolist_get", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - arguments = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_infolist_get (name, - API_STR2PTR(pointer), - arguments)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_next: move item pointer to next item in infolist - */ - -static int -weechat_tcl_api_infolist_next (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "infolist_next", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_infolist_next (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* infolist */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_infolist_prev: move item pointer to previous item in - * infolist - */ - -static int -weechat_tcl_api_infolist_prev (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int result, i; - - API_FUNC(1, "infolist_prev", API_RETURN_INT(0)); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - result = weechat_infolist_prev (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* infolist */ - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_infolist_reset_item_cursor: reset pointer to current item in - * infolist - */ - -static int -weechat_tcl_api_infolist_reset_item_cursor (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "infolist_reset_item_cursor", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_reset_item_cursor (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* infolist */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_infolist_fields: get list of fields for current item of - * infolist - */ - -static int -weechat_tcl_api_infolist_fields (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - const char *result; - int i; - - API_FUNC(1, "infolist_fields", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_infolist_fields (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* infolist */ - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_infolist_integer: get integer value of a variable in - * infolist - */ - -static int -weechat_tcl_api_infolist_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *infolist, *variable; - int result, i; - - API_FUNC(1, "infolist_integer", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - infolist = Tcl_GetStringFromObj (objv[1], &i); - variable = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_infolist_integer (API_STR2PTR(infolist), variable); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_infolist_string: get string value of a variable in infolist - */ - -static int -weechat_tcl_api_infolist_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *infolist, *variable; - const char *result; - int i; - - API_FUNC(1, "infolist_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = Tcl_GetStringFromObj (objv[1], &i); - variable = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_infolist_string (API_STR2PTR(infolist), variable); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_infolist_pointer: get pointer value of a variable in - * infolist - */ - -static int -weechat_tcl_api_infolist_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *infolist, *variable, *result; - int i; - - API_FUNC(1, "infolist_pointer", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = Tcl_GetStringFromObj (objv[1], &i); - variable = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_infolist_pointer (API_STR2PTR(infolist), variable)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_time: get time value of a variable in infolist - */ - -static int -weechat_tcl_api_infolist_time (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result, *infolist, *variable; - int i; - - API_FUNC(1, "infolist_time", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - infolist = Tcl_GetStringFromObj (objv[1], &i); - variable = Tcl_GetStringFromObj (objv[2], &i); - - timebuffer[0] = '\0'; - time = weechat_infolist_time (API_STR2PTR(infolist), variable); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_infolist_free: free infolist - */ - -static int -weechat_tcl_api_infolist_free (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - int i; - - API_FUNC(1, "infolist_free", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_infolist_free (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* infolist */ - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_hdata_get: get hdata - */ - -static int -weechat_tcl_api_hdata_get (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *name; - int i; - - API_FUNC(1, "hdata_get", API_RETURN_EMPTY); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - name = Tcl_GetStringFromObj (objv[1], &i); - - result = script_ptr2str (weechat_hdata_get (name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hdata_get_var_offset: get offset of variable in hdata - */ - -static int -weechat_tcl_api_hdata_get_var_offset (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *name; - int result, i; - - API_FUNC(1, "hdata_get_var_offset", API_RETURN_INT(0)); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hdata_get_var_offset (API_STR2PTR(hdata), name); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_hdata_get_var_type_string: get type of variable as string in - * hdata - */ - -static int -weechat_tcl_api_hdata_get_var_type_string (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *name; - const char *result; - int i; - - API_FUNC(1, "hdata_get_var_type_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hdata_get_var_type_string (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_hdata_get_var_array_size: get array_size for variable in - * hdata - */ - -static int -weechat_tcl_api_hdata_get_var_array_size (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - int result, i; - - API_FUNC(1, "hdata_get_var_array_size", API_RETURN_INT(-1)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(-1)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_get_var_array_size (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_hdata_get_var_array_size_string: get array size for variable - * in hdata (as string) - */ - -static int -weechat_tcl_api_hdata_get_var_array_size_string (ClientData clientData, - Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - const char *result; - int i; - - API_FUNC(1, "hdata_get_var_array_size_string", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_get_var_array_size_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_hdata_get_var_hdata: get hdata for variable in hdata - */ - -static int -weechat_tcl_api_hdata_get_var_hdata (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *name; - const char *result; - int i; - - API_FUNC(1, "hdata_get_var_hdata", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hdata_get_var_hdata (API_STR2PTR(hdata), name); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_hdata_get_list: get list pointer in hdata - */ - -static int -weechat_tcl_api_hdata_get_list (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *name, *result; - int i; - - API_FUNC(1, "hdata_get_list", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - name = Tcl_GetStringFromObj (objv[2], &i); - - result = script_ptr2str (weechat_hdata_get_list (API_STR2PTR(hdata), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hdata_check_pointer: check pointer with hdata/list - */ - -static int -weechat_tcl_api_hdata_check_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *list, *pointer; - int result, i; - - API_FUNC(1, "hdata_check_pointer", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - list = Tcl_GetStringFromObj (objv[2], &i); - pointer = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_check_pointer (API_STR2PTR(hdata), - API_STR2PTR(list), - API_STR2PTR(pointer)); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_hdata_move: move pointer to another element in list - */ - -static int -weechat_tcl_api_hdata_move (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *result; - int i, count; - - API_FUNC(1, "hdata_move", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - - if (Tcl_GetIntFromObj (interp, objv[3], &count) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = script_ptr2str (weechat_hdata_move (API_STR2PTR(hdata), - API_STR2PTR(pointer), - count)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hdata_char: get char value of a variable in structure - * using hdata - */ - -static int -weechat_tcl_api_hdata_char (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - int result, i; - - API_FUNC(1, "hdata_char", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = (int)weechat_hdata_char (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_hdata_integer: get integer value of a variable in structure - * using hdata - */ - -static int -weechat_tcl_api_hdata_integer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - int result, i; - - API_FUNC(1, "hdata_integer", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_integer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_INT(result); -} - -/* - * weechat_tcl_api_hdata_long: get long value of a variable in structure using - * hdata - */ - -static int -weechat_tcl_api_hdata_long (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - int result, i; - - API_FUNC(1, "hdata_long", API_RETURN_LONG(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_LONG(0)); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_long (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_LONG(result); -} - -/* - * weechat_tcl_api_hdata_string: get string value of a variable in structure - * using hdata - */ - -static int -weechat_tcl_api_hdata_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name; - const char *result; - int i; - - API_FUNC(1, "hdata_string", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = weechat_hdata_string (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_hdata_pointer: get pointer value of a variable in structure - * using hdata - */ - -static int -weechat_tcl_api_hdata_pointer (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *pointer, *name, *result; - int i; - - API_FUNC(1, "hdata_pointer", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result = script_ptr2str (weechat_hdata_pointer (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hdata_time: get time value of a variable in structure using - * hdata - */ - -static int -weechat_tcl_api_hdata_time (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - time_t time; - struct tm *date_tmp; - char timebuffer[64], *result, *hdata, *pointer, *name; - int i; - - API_FUNC(1, "hdata_time", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - timebuffer[0] = '\0'; - time = weechat_hdata_time (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name); - date_tmp = localtime (&time); - if (date_tmp) - strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp); - result = strdup (timebuffer); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_hdata_hashtable: get hashtable value of a variable in - * structure using hdata - */ - -static int -weechat_tcl_api_hdata_hashtable (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp, *result_dict; - char *hdata, *pointer, *name; - int i; - - API_FUNC(1, "hdata_hashtable", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - pointer = Tcl_GetStringFromObj (objv[2], &i); - name = Tcl_GetStringFromObj (objv[3], &i); - - result_dict = weechat_tcl_hashtable_to_dict ( - interp, - weechat_hdata_hashtable (API_STR2PTR(hdata), - API_STR2PTR(pointer), - name)); - - API_RETURN_OBJ(result_dict); -} - -/* - * weechat_tcl_api_hdata_get_string: get hdata property as string - */ - -static int -weechat_tcl_api_hdata_get_string (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *hdata, *property; - const char *result; - int i; - - API_FUNC(1, "hdata_get_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - hdata = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hdata_get_string (API_STR2PTR(hdata), property); - - API_RETURN_STRING(result); -} - -/* - * weechat_tcl_api_upgrade_new: create an upgrade file - */ - -static int -weechat_tcl_api_upgrade_new (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *result, *filename; - int i, write; - - API_FUNC(1, "upgrade_new", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - if (Tcl_GetIntFromObj (interp, objv[2], &write) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - filename = Tcl_GetStringFromObj (objv[1], &i); - - result = script_ptr2str (weechat_upgrade_new (filename, write)); - - API_RETURN_STRING_FREE(result); -} - -/* - * weechat_tcl_api_upgrade_write_object: write object in upgrade file - */ - -static int -weechat_tcl_api_upgrade_write_object (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *upgrade_file, *infolist; - int rc, i, object_id; - - API_FUNC(1, "upgrade_write_object", API_RETURN_INT(0)); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_INT(0)); - - if (Tcl_GetIntFromObj (interp, objv[2], &object_id) != TCL_OK) - API_WRONG_ARGS(API_RETURN_EMPTY); - - upgrade_file = Tcl_GetStringFromObj (objv[1], &i); - infolist = Tcl_GetStringFromObj (objv[3], &i); - - rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file), - object_id, - API_STR2PTR(infolist)); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_upgrade_read_cb: callback for reading an object in upgrade file - */ - -int -weechat_tcl_api_upgrade_read_cb (void *data, - struct t_upgrade_file *upgrade_file, - int object_id, - struct t_infolist *infolist) -{ - struct t_script_callback *script_callback; - void *func_argv[4]; - char empty_arg[1] = { '\0' }, str_object_id[32]; - int *rc, ret; - - script_callback = (struct t_script_callback *)data; - - if (script_callback && script_callback->function && script_callback->function[0]) - { - snprintf (str_object_id, sizeof (str_object_id), "%d", object_id); - - func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg; - func_argv[1] = script_ptr2str (upgrade_file); - func_argv[2] = str_object_id; - func_argv[3] = script_ptr2str (infolist); - - rc = (int *) weechat_tcl_exec (script_callback->script, - WEECHAT_SCRIPT_EXEC_INT, - script_callback->function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[1]) - free (func_argv[1]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -/* - * weechat_tcl_api_upgrade_read: read upgrade file - */ - -static int -weechat_tcl_api_upgrade_read (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *upgrade_file, *function, *data; - int i, rc; - - API_FUNC(1, "upgrade_read", API_RETURN_EMPTY); - if (objc < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - upgrade_file = Tcl_GetStringFromObj (objv[1], &i); - function = Tcl_GetStringFromObj (objv[2], &i); - data = Tcl_GetStringFromObj (objv[3], &i); - - rc = script_api_upgrade_read (weechat_tcl_plugin, - tcl_current_script, - API_STR2PTR(upgrade_file), - &weechat_tcl_api_upgrade_read_cb, - function, - data); - - API_RETURN_INT(rc); -} - -/* - * weechat_tcl_api_upgrade_close: close upgrade file - */ - -static int -weechat_tcl_api_upgrade_close (ClientData clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *CONST objv[]) -{ - Tcl_Obj *objp; - char *upgrade_file; - int i; - - API_FUNC(1, "upgrade_close", API_RETURN_ERROR); - if (objc < 2) - API_WRONG_ARGS(API_RETURN_INT(0)); - - upgrade_file = Tcl_GetStringFromObj (objv[1], &i); - - weechat_upgrade_close (API_STR2PTR(upgrade_file)); - - API_RETURN_OK; -} - -/* - * weechat_tcl_api_init: initialize subroutines - */ - -void weechat_tcl_api_init (Tcl_Interp *interp) -{ - int i; - Tcl_Obj *objp; - - /* standard initializer */ - Tcl_Init (interp); - - Tcl_Eval (interp,"namespace eval weechat {}"); - - /* interface constants */ - /* set variables, TODO: make them unmodifiable (thru Tcl_TraceVar) ? */ - /* NOTE: it is not good for performance to convert "defines" to Tcl_Obj */ - objp = Tcl_NewIntObj (WEECHAT_RC_OK); - Tcl_IncrRefCount (objp); - - Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_RC_OK_EAT); - Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK_EAT", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_RC_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_RC_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetIntObj (objp, WEECHAT_CONFIG_READ_OK); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_READ_OK", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_READ_MEMORY_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_READ_MEMORY_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_READ_FILE_NOT_FOUND); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_READ_FILE_NOT_FOUND", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_WRITE_OK); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_WRITE_OK", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_WRITE_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_WRITE_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_WRITE_MEMORY_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_WRITE_MEMORY_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_SET_OK_CHANGED); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_SET_OK_CHANGED", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_SET_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_SET_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_RESET", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_CONFIG_OPTION_UNSET_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_CONFIG_OPTION_UNSET_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetStringObj (objp, WEECHAT_LIST_POS_SORT, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_LIST_POS_SORT", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_LIST_POS_BEGINNING, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_LIST_POS_BEGINNING", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_LIST_POS_END, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_LIST_POS_END", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetStringObj (objp, WEECHAT_HOTLIST_LOW, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOTLIST_LOW", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_HOTLIST_MESSAGE, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOTLIST_MESSAGE", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_HOTLIST_PRIVATE, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOTLIST_PRIVATE", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_HOTLIST_HIGHLIGHT, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOTLIST_HIGHLIGHT", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetIntObj (objp, WEECHAT_HOOK_PROCESS_RUNNING); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_PROCESS_RUNNING", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_PROCESS_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_PROCESS_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_OK); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_OK", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_PROXY_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_PROXY_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_MEMORY_ERROR); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_MEMORY_ERROR", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetIntObj (objp, WEECHAT_HOOK_CONNECT_TIMEOUT); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_CONNECT_TIMEOUT", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_SetStringObj (objp, WEECHAT_HOOK_SIGNAL_STRING, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_SIGNAL_STRING", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_HOOK_SIGNAL_INT, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_SIGNAL_INT", Tcl_GetStringFromObj (objp, &i), 0); - Tcl_SetStringObj (objp, WEECHAT_HOOK_SIGNAL_POINTER, -1); - Tcl_SetVar (interp, "weechat::WEECHAT_HOOK_SIGNAL_POINTER", Tcl_GetStringFromObj (objp, &i), 0); - - Tcl_DecrRefCount (objp); - - /* interface functions */ - API_DEF_FUNC(register); - API_DEF_FUNC(plugin_get_name); - API_DEF_FUNC(charset_set); - API_DEF_FUNC(iconv_to_internal); - API_DEF_FUNC(iconv_from_internal); - API_DEF_FUNC(gettext); - API_DEF_FUNC(ngettext); - API_DEF_FUNC(string_match); - API_DEF_FUNC(string_has_highlight); - API_DEF_FUNC(string_has_highlight_regex); - API_DEF_FUNC(string_mask_to_regex); - API_DEF_FUNC(string_remove_color); - API_DEF_FUNC(string_is_command_char); - API_DEF_FUNC(string_input_for_buffer); - API_DEF_FUNC(mkdir_home); - API_DEF_FUNC(mkdir); - API_DEF_FUNC(mkdir_parents); - API_DEF_FUNC(list_new); - API_DEF_FUNC(list_add); - API_DEF_FUNC(list_search); - API_DEF_FUNC(list_search_pos); - API_DEF_FUNC(list_casesearch); - API_DEF_FUNC(list_casesearch_pos); - API_DEF_FUNC(list_get); - API_DEF_FUNC(list_set); - API_DEF_FUNC(list_next); - API_DEF_FUNC(list_prev); - API_DEF_FUNC(list_string); - API_DEF_FUNC(list_size); - API_DEF_FUNC(list_remove); - API_DEF_FUNC(list_remove_all); - API_DEF_FUNC(list_free); - API_DEF_FUNC(config_new); - API_DEF_FUNC(config_new_section); - API_DEF_FUNC(config_search_section); - API_DEF_FUNC(config_new_option); - API_DEF_FUNC(config_search_option); - API_DEF_FUNC(config_string_to_boolean); - API_DEF_FUNC(config_option_reset); - API_DEF_FUNC(config_option_set); - API_DEF_FUNC(config_option_set_null); - API_DEF_FUNC(config_option_unset); - API_DEF_FUNC(config_option_rename); - API_DEF_FUNC(config_option_is_null); - API_DEF_FUNC(config_option_default_is_null); - API_DEF_FUNC(config_boolean); - API_DEF_FUNC(config_boolean_default); - API_DEF_FUNC(config_integer); - API_DEF_FUNC(config_integer_default); - API_DEF_FUNC(config_string); - API_DEF_FUNC(config_string_default); - API_DEF_FUNC(config_color); - API_DEF_FUNC(config_color_default); - API_DEF_FUNC(config_write_option); - API_DEF_FUNC(config_write_line); - API_DEF_FUNC(config_write); - API_DEF_FUNC(config_read); - API_DEF_FUNC(config_reload); - API_DEF_FUNC(config_option_free); - API_DEF_FUNC(config_section_free_options); - API_DEF_FUNC(config_section_free); - API_DEF_FUNC(config_free); - API_DEF_FUNC(config_get); - API_DEF_FUNC(config_get_plugin); - API_DEF_FUNC(config_is_set_plugin); - API_DEF_FUNC(config_set_plugin); - API_DEF_FUNC(config_set_desc_plugin); - API_DEF_FUNC(config_unset_plugin); - API_DEF_FUNC(key_bind); - API_DEF_FUNC(key_unbind); - API_DEF_FUNC(prefix); - API_DEF_FUNC(color); - API_DEF_FUNC(print); - API_DEF_FUNC(print_date_tags); - API_DEF_FUNC(print_y); - API_DEF_FUNC(log_print); - API_DEF_FUNC(hook_command); - API_DEF_FUNC(hook_command_run); - API_DEF_FUNC(hook_timer); - API_DEF_FUNC(hook_fd); - API_DEF_FUNC(hook_process); - API_DEF_FUNC(hook_process_hashtable); - API_DEF_FUNC(hook_connect); - API_DEF_FUNC(hook_print); - API_DEF_FUNC(hook_signal); - API_DEF_FUNC(hook_signal_send); - API_DEF_FUNC(hook_hsignal); - API_DEF_FUNC(hook_hsignal_send); - API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_list_add); - API_DEF_FUNC(hook_modifier); - API_DEF_FUNC(hook_modifier_exec); - API_DEF_FUNC(hook_info); - API_DEF_FUNC(hook_info_hashtable); - API_DEF_FUNC(hook_infolist); - API_DEF_FUNC(hook_focus); - API_DEF_FUNC(unhook); - API_DEF_FUNC(unhook_all); - API_DEF_FUNC(buffer_new); - API_DEF_FUNC(buffer_search); - API_DEF_FUNC(buffer_search_main); - API_DEF_FUNC(current_buffer); - API_DEF_FUNC(buffer_clear); - API_DEF_FUNC(buffer_close); - API_DEF_FUNC(buffer_merge); - API_DEF_FUNC(buffer_unmerge); - API_DEF_FUNC(buffer_get_integer); - API_DEF_FUNC(buffer_get_string); - API_DEF_FUNC(buffer_get_pointer); - API_DEF_FUNC(buffer_set); - API_DEF_FUNC(buffer_string_replace_local_var); - API_DEF_FUNC(buffer_match_list); - API_DEF_FUNC(current_window); - API_DEF_FUNC(window_search_with_buffer); - API_DEF_FUNC(window_get_integer); - API_DEF_FUNC(window_get_string); - API_DEF_FUNC(window_get_pointer); - API_DEF_FUNC(window_set_title); - API_DEF_FUNC(nicklist_add_group); - API_DEF_FUNC(nicklist_search_group); - API_DEF_FUNC(nicklist_add_nick); - API_DEF_FUNC(nicklist_search_nick); - API_DEF_FUNC(nicklist_remove_group); - API_DEF_FUNC(nicklist_remove_nick); - API_DEF_FUNC(nicklist_remove_all); - API_DEF_FUNC(nicklist_group_get_integer); - API_DEF_FUNC(nicklist_group_get_string); - API_DEF_FUNC(nicklist_group_get_pointer); - API_DEF_FUNC(nicklist_group_set); - API_DEF_FUNC(nicklist_nick_get_integer); - API_DEF_FUNC(nicklist_nick_get_string); - API_DEF_FUNC(nicklist_nick_get_pointer); - API_DEF_FUNC(nicklist_nick_set); - API_DEF_FUNC(bar_item_search); - API_DEF_FUNC(bar_item_new); - API_DEF_FUNC(bar_item_update); - API_DEF_FUNC(bar_item_remove); - API_DEF_FUNC(bar_search); - API_DEF_FUNC(bar_new); - API_DEF_FUNC(bar_set); - API_DEF_FUNC(bar_update); - API_DEF_FUNC(bar_remove); - API_DEF_FUNC(command); - API_DEF_FUNC(info_get); - API_DEF_FUNC(info_get_hashtable); - API_DEF_FUNC(infolist_new); - API_DEF_FUNC(infolist_new_item); - API_DEF_FUNC(infolist_new_var_integer); - API_DEF_FUNC(infolist_new_var_string); - API_DEF_FUNC(infolist_new_var_pointer); - API_DEF_FUNC(infolist_new_var_time); - API_DEF_FUNC(infolist_get); - API_DEF_FUNC(infolist_next); - API_DEF_FUNC(infolist_prev); - API_DEF_FUNC(infolist_reset_item_cursor); - API_DEF_FUNC(infolist_fields); - API_DEF_FUNC(infolist_integer); - API_DEF_FUNC(infolist_string); - API_DEF_FUNC(infolist_pointer); - API_DEF_FUNC(infolist_time); - API_DEF_FUNC(infolist_free); - API_DEF_FUNC(hdata_get); - API_DEF_FUNC(hdata_get_var_offset); - API_DEF_FUNC(hdata_get_var_type_string); - API_DEF_FUNC(hdata_get_var_array_size); - API_DEF_FUNC(hdata_get_var_array_size_string); - API_DEF_FUNC(hdata_get_var_hdata); - API_DEF_FUNC(hdata_get_list); - API_DEF_FUNC(hdata_check_pointer); - API_DEF_FUNC(hdata_move); - API_DEF_FUNC(hdata_char); - API_DEF_FUNC(hdata_integer); - API_DEF_FUNC(hdata_long); - API_DEF_FUNC(hdata_string); - API_DEF_FUNC(hdata_pointer); - API_DEF_FUNC(hdata_time); - API_DEF_FUNC(hdata_hashtable); - API_DEF_FUNC(hdata_get_string); - API_DEF_FUNC(upgrade_new); - API_DEF_FUNC(upgrade_write_object); - API_DEF_FUNC(upgrade_read); - API_DEF_FUNC(upgrade_close); -} diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.h b/src/plugins/scripts/tcl/weechat-tcl-api.h deleted file mode 100644 index 8c1f60392..000000000 --- a/src/plugins/scripts/tcl/weechat-tcl-api.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> - * Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_TCL_API_H -#define __WEECHAT_TCL_API_H 1 - -extern int weechat_tcl_api_buffer_input_data_cb (void *data, - struct t_gui_buffer *buffer, - const char *input_data); -extern int weechat_tcl_api_buffer_close_cb (void *data, - struct t_gui_buffer *buffer); -extern void weechat_tcl_api_init (Tcl_Interp *interp); - -#endif /* __WEECHAT_TCL_API_H */ diff --git a/src/plugins/scripts/tcl/weechat-tcl.c b/src/plugins/scripts/tcl/weechat-tcl.c deleted file mode 100644 index a93fc551b..000000000 --- a/src/plugins/scripts/tcl/weechat-tcl.c +++ /dev/null @@ -1,753 +0,0 @@ -/* - * Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> - * Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * weechat-tcl.c: tcl plugin for WeeChat - */ - -#undef _ - -#include <tcl.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <stdlib.h> -#include <string.h> - -#include "../../weechat-plugin.h" -#include "../script.h" -#include "weechat-tcl.h" -#include "weechat-tcl-api.h" - - -WEECHAT_PLUGIN_NAME(TCL_PLUGIN_NAME); -WEECHAT_PLUGIN_DESCRIPTION(N_("Support of tcl scripts")); -WEECHAT_PLUGIN_AUTHOR("Dmitry Kobylin <fnfal@academ.tsc.ru>"); -WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); -WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); - -struct t_weechat_plugin *weechat_tcl_plugin = NULL; - -int tcl_quiet = 0; -struct t_plugin_script *tcl_scripts = NULL; -struct t_plugin_script *last_tcl_script = NULL; -struct t_plugin_script *tcl_current_script = NULL; -struct t_plugin_script *tcl_registered_script = NULL; -const char *tcl_current_script_filename = NULL; - -/* - * string used to execute action "install": - * when signal "tcl_install_script" is received, name of string - * is added to this string, to be installed later by a timer (when nothing is - * running in script) - */ -char *tcl_action_install_list = NULL; - -/* - * string used to execute action "remove": - * when signal "tcl_remove_script" is received, name of string - * is added to this string, to be removed later by a timer (when nothing is - * running in script) - */ -char *tcl_action_remove_list = NULL; - -Tcl_Interp* cinterp; - - -/* - * weechat_tcl_hashtable_map_cb: callback called for each key/value in a - * hashtable - */ - -void -weechat_tcl_hashtable_map_cb (void *data, - struct t_hashtable *hashtable, - const char *key, - const char *value) -{ - void **data_array; - Tcl_Interp *interp; - Tcl_Obj *dict; - - /* make C compiler happy */ - (void) hashtable; - - data_array = (void **)data; - interp = data_array[0]; - dict = data_array[1]; - - Tcl_DictObjPut (interp, dict, - Tcl_NewStringObj (key, -1), - Tcl_NewStringObj (value, -1)); -} - -/* - * weechat_tcl_hashtable_to_dict: get tcl dict with a WeeChat hashtable - */ - -Tcl_Obj * -weechat_tcl_hashtable_to_dict (Tcl_Interp *interp, - struct t_hashtable *hashtable) -{ - Tcl_Obj *dict; - void *data[2]; - - dict = Tcl_NewDictObj (); - if (!dict) - return NULL; - - data[0] = interp; - data[1] = dict; - - weechat_hashtable_map_string (hashtable, - &weechat_tcl_hashtable_map_cb, - data); - - return dict; -} - -/* - * weechat_tcl_dict_to_hashtable: get WeeChat hashtable with tcl dict - * Hashtable returned has type string for - * both keys and values - * Note: hashtable has to be released after - * use with call to weechat_hashtable_free() - */ - -struct t_hashtable * -weechat_tcl_dict_to_hashtable (Tcl_Interp *interp, Tcl_Obj *dict, - int hashtable_size) -{ - struct t_hashtable *hashtable; - Tcl_DictSearch search; - Tcl_Obj *key, *value; - int done; - - hashtable = weechat_hashtable_new (hashtable_size, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (!hashtable) - return NULL; - - if (Tcl_DictObjFirst (interp, dict, &search, &key, &value, &done) == TCL_OK) - { - for (; !done ; Tcl_DictObjNext(&search, &key, &value, &done)) - { - weechat_hashtable_set (hashtable, - Tcl_GetString (key), - Tcl_GetString (value)); - } - } - Tcl_DictObjDone(&search); - - return hashtable; -} - -/* - * weechat_tcl_exec: execute a tcl function - */ - -void * -weechat_tcl_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv) -{ - int argc, i, llength; - int *ret_i; - char *ret_cv; - void *ret_val; - Tcl_Obj *cmdlist; - Tcl_Interp *interp; - struct t_plugin_script *old_tcl_script; - - old_tcl_script = tcl_current_script; - tcl_current_script = script; - interp = (Tcl_Interp*)script->interpreter; - - if (function && function[0]) - { - cmdlist = Tcl_NewListObj (0, NULL); - Tcl_IncrRefCount (cmdlist); /* +1 */ - Tcl_ListObjAppendElement (interp, cmdlist, Tcl_NewStringObj (function,-1)); - } - else - { - tcl_current_script = old_tcl_script; - return NULL; - } - - if (format && format[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - Tcl_ListObjAppendElement (interp, cmdlist, - Tcl_NewStringObj (argv[i], -1)); - break; - case 'i': /* integer */ - Tcl_ListObjAppendElement (interp, cmdlist, - Tcl_NewIntObj (*((int *)argv[i]))); - break; - case 'h': /* hash */ - Tcl_ListObjAppendElement (interp, cmdlist, - weechat_tcl_hashtable_to_dict (interp, argv[i])); - break; - } - } - } - - if (Tcl_ListObjLength (interp, cmdlist, &llength) != TCL_OK) - llength = 0; - - if (Tcl_EvalObjEx (interp, cmdlist, TCL_EVAL_DIRECT) == TCL_OK) - { - Tcl_ListObjReplace (interp, cmdlist, 0, llength, 0, NULL); /* remove elements, decrement their ref count */ - Tcl_DecrRefCount (cmdlist); /* -1 */ - ret_val = NULL; - if (ret_type == WEECHAT_SCRIPT_EXEC_STRING) - { - ret_cv = Tcl_GetStringFromObj (Tcl_GetObjResult (interp), &i); - if (ret_cv) - ret_val = (void *)strdup (ret_cv); - else - ret_val = NULL; - } - else if ( ret_type == WEECHAT_SCRIPT_EXEC_INT - && Tcl_GetIntFromObj (interp, Tcl_GetObjResult (interp), &i) == TCL_OK) - { - ret_i = (int *)malloc (sizeof (*ret_i)); - if (ret_i) - *ret_i = i; - ret_val = (void *)ret_i; - } - else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) - { - ret_val = weechat_tcl_dict_to_hashtable (interp, - Tcl_GetObjResult (interp), - WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE); - } - - tcl_current_script = old_tcl_script; - if (ret_val) - return ret_val; - - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"%s\" must return a " - "valid value"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, function); - return NULL; - } - - Tcl_ListObjReplace (interp, cmdlist, 0, llength, 0, NULL); /* remove elements, decrement their ref count */ - Tcl_DecrRefCount (cmdlist); /* -1 */ - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to run function \"%s\": %s"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, function, - Tcl_GetStringFromObj (Tcl_GetObjResult (interp), &i)); - tcl_current_script = old_tcl_script; - - return NULL; -} - -/* - * weechat_tcl_load: load a Tcl script - */ - -int -weechat_tcl_load (const char *filename) -{ - int i; - Tcl_Interp *interp; - struct stat buf; - - if (stat (filename, &buf) != 0) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not found"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, filename); - return 0; - } - - if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - TCL_PLUGIN_NAME, filename); - } - - tcl_current_script = NULL; - tcl_registered_script = NULL; - - if (!(interp = Tcl_CreateInterp ())) { - weechat_printf (NULL, - weechat_gettext ("%s%s: unable to create new " - "interpreter"), - weechat_prefix ("error"), TCL_PLUGIN_NAME); - return 0; - } - tcl_current_script_filename = filename; - - weechat_tcl_api_init (interp); - - if (Tcl_EvalFile (interp, filename) != TCL_OK) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: error occurred while " - "parsing file \"%s\": %s"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, filename, - Tcl_GetStringFromObj (Tcl_GetObjResult (interp), &i)); - /* this ok, maybe "register" was called, so not return */ - /* return 0; */ - } - - if (!tcl_registered_script) - { - weechat_printf (NULL, - weechat_gettext ("%s%s: function \"register\" not " - "found (or failed) in file \"%s\""), - weechat_prefix ("error"), TCL_PLUGIN_NAME, filename); - Tcl_DeleteInterp (interp); - return 0; - } - tcl_current_script = tcl_registered_script; - - /* - * set input/close callbacks for buffers created by this script - * (to restore callbacks after upgrade) - */ - script_set_buffer_callbacks (weechat_tcl_plugin, - tcl_scripts, - tcl_current_script, - &weechat_tcl_api_buffer_input_data_cb, - &weechat_tcl_api_buffer_close_cb); - - return 1; -} - -/* - * weechat_tcl_load_cb: callback for weechat_script_auto_load() function - */ - -void -weechat_tcl_load_cb (void *data, const char *filename) -{ - /* make C compiler happy */ - (void) data; - - weechat_tcl_load (filename); -} - -/* - * weechat_tcl_unload: unload a Tcl script - */ - -void -weechat_tcl_unload (struct t_plugin_script *script) -{ - Tcl_Interp* interp; - int *rc; - - if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet) - { - weechat_printf (NULL, - weechat_gettext ("%s: unloading script \"%s\""), - TCL_PLUGIN_NAME, script->name); - } - - if (script->shutdown_func && script->shutdown_func[0]) - { - rc = (int *)weechat_tcl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - script->shutdown_func, - NULL, NULL); - if (rc) - free (rc); - } - - interp = (Tcl_Interp*)script->interpreter; - - if (tcl_current_script == script) - tcl_current_script = (tcl_current_script->prev_script) ? - tcl_current_script->prev_script : tcl_current_script->next_script; - - script_remove (weechat_tcl_plugin, &tcl_scripts, &last_tcl_script, script); - - Tcl_DeleteInterp(interp); -} - -/* - * weechat_tcl_unload_name: unload a Tcl script by name - */ - -void -weechat_tcl_unload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - - ptr_script = script_search (weechat_tcl_plugin, tcl_scripts, name); - if (ptr_script) - { - weechat_tcl_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - TCL_PLUGIN_NAME, name); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, name); - } -} - -/* - * weechat_tcl_unload_all: unload all Tcl scripts - */ - -void -weechat_tcl_unload_all () -{ - while (tcl_scripts) - { - weechat_tcl_unload (tcl_scripts); - } -} - -/* - * weechat_tcl_reload_name: reload a Tcl script by name - */ - -void -weechat_tcl_reload_name (const char *name) -{ - struct t_plugin_script *ptr_script; - char *filename; - - ptr_script = script_search (weechat_tcl_plugin, tcl_scripts, name); - if (ptr_script) - { - filename = strdup (ptr_script->filename); - if (filename) - { - weechat_tcl_unload (ptr_script); - weechat_printf (NULL, - weechat_gettext ("%s: script \"%s\" unloaded"), - TCL_PLUGIN_NAME, name); - weechat_tcl_load (filename); - free (filename); - } - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: script \"%s\" not loaded"), - weechat_prefix ("error"), TCL_PLUGIN_NAME, name); - } -} - -/* - * weechat_tcl_command_cb: callback for "/tcl" command - */ - -int -weechat_tcl_command_cb (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) -{ - char *path_script; - - /* make C compiler happy */ - (void) data; - (void) buffer; - - if (argc == 1) - { - script_display_list (weechat_tcl_plugin, tcl_scripts, - NULL, 0); - } - else if (argc == 2) - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_tcl_plugin, tcl_scripts, - NULL, 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_tcl_plugin, tcl_scripts, - NULL, 1); - } - else if (weechat_strcasecmp (argv[1], "autoload") == 0) - { - script_auto_load (weechat_tcl_plugin, &weechat_tcl_load_cb); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - weechat_tcl_unload_all (); - script_auto_load (weechat_tcl_plugin, &weechat_tcl_load_cb); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - weechat_tcl_unload_all (); - } - } - else - { - if (weechat_strcasecmp (argv[1], "list") == 0) - { - script_display_list (weechat_tcl_plugin, tcl_scripts, - argv_eol[2], 0); - } - else if (weechat_strcasecmp (argv[1], "listfull") == 0) - { - script_display_list (weechat_tcl_plugin, tcl_scripts, - argv_eol[2], 1); - } - else if (weechat_strcasecmp (argv[1], "load") == 0) - { - /* load Tcl script */ - path_script = script_search_path (weechat_tcl_plugin, - argv_eol[2]); - weechat_tcl_load ((path_script) ? path_script : argv_eol[2]); - if (path_script) - free (path_script); - } - else if (weechat_strcasecmp (argv[1], "reload") == 0) - { - /* reload one Tcl script */ - weechat_tcl_reload_name (argv_eol[2]); - } - else if (weechat_strcasecmp (argv[1], "unload") == 0) - { - /* unload Tcl script */ - weechat_tcl_unload_name (argv_eol[2]); - } - else - { - weechat_printf (NULL, - weechat_gettext ("%s%s: unknown option for " - "command \"%s\""), - weechat_prefix ("error"), TCL_PLUGIN_NAME, "tcl"); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_tcl_completion_cb: callback for script completion - */ - -int -weechat_tcl_completion_cb (void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* make C compiler happy */ - (void) data; - (void) completion_item; - (void) buffer; - - script_completion (weechat_tcl_plugin, completion, tcl_scripts); - - return WEECHAT_RC_OK; -} - -/* - * weechat_tcl_infolist_cb: callback for infolist - */ - -struct t_infolist * -weechat_tcl_infolist_cb (void *data, const char *infolist_name, - void *pointer, const char *arguments) -{ - /* make C compiler happy */ - (void) data; - - if (!infolist_name || !infolist_name[0]) - return NULL; - - if (weechat_strcasecmp (infolist_name, "tcl_script") == 0) - { - return script_infolist_list_scripts (weechat_tcl_plugin, - tcl_scripts, pointer, - arguments); - } - - return NULL; -} - -/* - * weechat_tcl_signal_debug_dump_cb: dump Tcl plugin data in WeeChat log file - */ - -int -weechat_tcl_signal_debug_dump_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (!signal_data - || (weechat_strcasecmp ((char *)signal_data, TCL_PLUGIN_NAME) == 0)) - { - script_print_log (weechat_tcl_plugin, tcl_scripts); - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_tcl_signal_buffer_closed_cb: callback called when a buffer is closed - */ - -int -weechat_tcl_signal_buffer_closed_cb (void *data, const char *signal, - const char *type_data, void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - - if (signal_data) - script_remove_buffer_callbacks (tcl_scripts, signal_data); - - return WEECHAT_RC_OK; -} - -/* - * weechat_tcl_timer_action_cb: timer for executing actions - */ - -int -weechat_tcl_timer_action_cb (void *data, int remaining_calls) -{ - /* make C compiler happy */ - (void) remaining_calls; - - if (data) - { - if (data == &tcl_action_install_list) - { - script_action_install (weechat_tcl_plugin, - tcl_scripts, - &weechat_tcl_unload, - &weechat_tcl_load, - &tcl_action_install_list); - } - else if (data == &tcl_action_remove_list) - { - script_action_remove (weechat_tcl_plugin, - tcl_scripts, - &weechat_tcl_unload, - &tcl_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_tcl_signal_script_action_cb: callback called when a script action - * is asked (install/remove a script) - */ - -int -weechat_tcl_signal_script_action_cb (void *data, const char *signal, - const char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (strcmp (signal, "tcl_script_install") == 0) - { - script_action_add (&tcl_action_install_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_tcl_timer_action_cb, - &tcl_action_install_list); - } - else if (strcmp (signal, "tcl_script_remove") == 0) - { - script_action_add (&tcl_action_remove_list, - (const char *)signal_data); - weechat_hook_timer (1, 0, 1, - &weechat_tcl_timer_action_cb, - &tcl_action_remove_list); - } - } - - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_init: initialize Tcl plugin - */ - -int -weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) -{ - struct t_plugin_script_init init; - - weechat_tcl_plugin = plugin; - - init.callback_command = &weechat_tcl_command_cb; - init.callback_completion = &weechat_tcl_completion_cb; - init.callback_infolist = &weechat_tcl_infolist_cb; - init.callback_signal_debug_dump = &weechat_tcl_signal_debug_dump_cb; - init.callback_signal_buffer_closed = &weechat_tcl_signal_buffer_closed_cb; - init.callback_signal_script_action = &weechat_tcl_signal_script_action_cb; - init.callback_load_file = &weechat_tcl_load_cb; - - tcl_quiet = 1; - script_init (weechat_tcl_plugin, argc, argv, &init); - tcl_quiet = 0; - - script_display_short_list (weechat_tcl_plugin, - tcl_scripts); - - /* init ok */ - return WEECHAT_RC_OK; -} - -/* - * weechat_plugin_end: end Tcl plugin - */ - -int -weechat_plugin_end (struct t_weechat_plugin *plugin) -{ - /* unload all scripts */ - tcl_quiet = 1; - script_end (plugin, &tcl_scripts, &weechat_tcl_unload_all); - tcl_quiet = 0; - - return WEECHAT_RC_OK; -} diff --git a/src/plugins/scripts/tcl/weechat-tcl.h b/src/plugins/scripts/tcl/weechat-tcl.h deleted file mode 100644 index 62a258885..000000000 --- a/src/plugins/scripts/tcl/weechat-tcl.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008-2010 Dmitry Kobylin <fnfal@academ.tsc.ru> - * Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org> - * - * This file is part of WeeChat, the extensible chat client. - * - * WeeChat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * WeeChat is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __WEECHAT_TCL_H -#define __WEECHAT_TCL_H 1 - -#define weechat_plugin weechat_tcl_plugin -#define TCL_PLUGIN_NAME "tcl" - -#define TCL_CURRENT_SCRIPT_NAME ((tcl_current_script) ? tcl_current_script->name : "-") - -extern struct t_weechat_plugin *weechat_tcl_plugin; - -extern int tcl_quiet; -extern struct t_plugin_script *tcl_scripts; -extern struct t_plugin_script *last_tcl_script; -extern struct t_plugin_script *tcl_current_script; -extern struct t_plugin_script *tcl_registered_script; -extern const char *tcl_current_script_filename; - -extern Tcl_Obj *weechat_tcl_hashtable_to_dict (Tcl_Interp *interp, - struct t_hashtable *hashtable); -extern struct t_hashtable *weechat_tcl_dict_to_hashtable (Tcl_Interp *interp, - Tcl_Obj *dict, - int hashtable_size); -extern void *weechat_tcl_exec (struct t_plugin_script *script, - int ret_type, const char *function, - const char *format, void **argv); - -#endif /* __WEECHAT_TCL_H */ |