Skip to content
Permalink
Browse files

guile: add support of Guile 2.2 (issue #1098)

  • Loading branch information...
flashcode committed Nov 21, 2018
1 parent e1a4612 commit 387a44f5ece0af6e805bd1a469d1aa1358d60d98
@@ -33,7 +33,7 @@ endif()

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_search_module(GUILE guile-2.0)
pkg_search_module(GUILE guile-2.2 guile-2.0)
if(GUILE_FOUND)
# check if variable "scm_install_gmp_memory_functions" exists
set(CMAKE_REQUIRED_INCLUDES ${GUILE_INCLUDE_DIRS})
@@ -727,7 +727,7 @@ if test "x$enable_guile" = "xyes" ; then
guile_found="no"
AC_MSG_CHECKING(for Guile headers and libraries)
echo
for v in "2.0" ; do
for v in "2.2" "2.0" ; do
pkgconfig_guile_found=`$PKGCONFIG --exists guile-$v 2>/dev/null`
if test "x$?" = "x0" ; then
GUILE_VERSION=`$PKGCONFIG --modversion guile-$v`
@@ -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);
@@ -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.
@@ -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 */

0 comments on commit 387a44f

Please sign in to comment.
You can’t perform that action at this time.