diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2018-11-21 21:31:07 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-09-21 14:48:05 +0200 |
commit | 387a44f5ece0af6e805bd1a469d1aa1358d60d98 (patch) | |
tree | 22752565d14406bda5e508474bdb67deaa49d22c /src/plugins/guile | |
parent | e1a461279731877ad66298d9c0576997474453af (diff) | |
download | weechat-387a44f5ece0af6e805bd1a469d1aa1358d60d98.zip |
guile: add support of Guile 2.2 (issue #1098)
Diffstat (limited to 'src/plugins/guile')
-rw-r--r-- | src/plugins/guile/weechat-guile-api.c | 17 | ||||
-rw-r--r-- | src/plugins/guile/weechat-guile.c | 52 | ||||
-rw-r--r-- | src/plugins/guile/weechat-guile.h | 11 |
3 files changed, 77 insertions, 3 deletions
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 331ce0e64..d54eb11ee 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -4874,10 +4874,17 @@ weechat_guile_api_upgrade_close (SCM upgrade_file) void weechat_guile_api_module_init (void *data) { - scm_t_bits port_type; +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) + /* Guile >= 2.2 */ + scm_t_port_type *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_c_make_port (port_type, 0, 0); +#else + /* Guile < 2.2 */ + scm_t_bits port_type; port_type = scm_make_port_type ("weechat_stdout", &weechat_guile_port_fill_input, @@ -4886,6 +4893,10 @@ weechat_guile_api_module_init (void *data) 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); +#endif + + /* make C compiler happy */ + (void) data; /* interface functions */ API_DEF_FUNC(register, 7); diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index 0ea420582..e9056ad36 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -1127,6 +1127,21 @@ weechat_guile_signal_script_action_cb (const void *pointer, void *data, * Fills input. */ +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +size_t +weechat_guile_port_fill_input (SCM port, SCM dst, size_t start, size_t count) +{ + /* make C compiler happy */ + (void) port; + (void) dst; + (void) start; + (void) count; + + return ' '; +} +#else +/* Guile < 2.2 */ int weechat_guile_port_fill_input (SCM port) { @@ -1135,11 +1150,47 @@ weechat_guile_port_fill_input (SCM port) return ' '; } +#endif /* * Write. */ +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +size_t +weechat_guile_port_write (SCM port, SCM src, size_t start, size_t count) +{ + char *data2, *ptr_data, *ptr_newline; + const char *data; + + /* make C compiler happy */ + (void) port; + + data = scm_to_locale_string (src); + + data2 = malloc (count + 1); + if (!data2) + return 0; + + memcpy (data2, data + start, count); + data2[count] = '\0'; + + ptr_data = data2; + while ((ptr_newline = strchr (ptr_data, '\n')) != NULL) + { + ptr_newline[0] = '\0'; + weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_guile_output_flush (); + ptr_newline[0] = '\n'; + ptr_data = ++ptr_newline; + } + weechat_string_dyn_concat (guile_buffer_output, ptr_data); + + return count; +} +#else +/* Guile < 2.2 */ void weechat_guile_port_write (SCM port, const void *data, size_t size) { @@ -1166,6 +1217,7 @@ weechat_guile_port_write (SCM port, const void *data, size_t size) } weechat_string_dyn_concat (guile_buffer_output, ptr_data); } +#endif /* * Initializes guile plugin. diff --git a/src/plugins/guile/weechat-guile.h b/src/plugins/guile/weechat-guile.h index ee1a7a144..b21da36a6 100644 --- a/src/plugins/guile/weechat-guile.h +++ b/src/plugins/guile/weechat-guile.h @@ -20,6 +20,8 @@ #ifndef WEECHAT_PLUGIN_GUILE_H #define WEECHAT_PLUGIN_GUILE_H +#include <libguile.h> + #define weechat_plugin weechat_guile_plugin #define GUILE_PLUGIN_NAME "guile" @@ -45,7 +47,16 @@ extern struct t_hashtable *weechat_guile_alist_to_hashtable (SCM dict, extern void *weechat_guile_exec (struct t_plugin_script *script, int ret_type, const char *function, char *format, void **argv); +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +extern size_t weechat_guile_port_fill_input (SCM port, SCM dst, + size_t start, size_t count); +extern size_t weechat_guile_port_write (SCM port, SCM src, + size_t start, size_t count); +#else +/* Guile < 2.2 */ extern int weechat_guile_port_fill_input (SCM port); extern void weechat_guile_port_write (SCM port, const void *data, size_t size); +#endif #endif /* WEECHAT_PLUGIN_GUILE_H */ |