From d176e70202a5ef3c6af8fcef0fdcc5733d641f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 23 Feb 2019 22:47:24 +0100 Subject: Reenable guile stuff. --- guile_interface.h | 15 +++++++ guile_interface.h__ | 15 ------- guile_interface.scm.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ guile_interface.scm.c__ | 91 ---------------------------------------- guile_interface.x__ | 6 --- guile_type_helpers.c | 18 ++++++++ guile_type_helpers.c__ | 18 -------- guile_type_helpers.h | 13 ++++++ guile_type_helpers.h__ | 13 ------ 9 files changed, 155 insertions(+), 143 deletions(-) create mode 100644 guile_interface.h delete mode 100644 guile_interface.h__ create mode 100644 guile_interface.scm.c delete mode 100644 guile_interface.scm.c__ delete mode 100644 guile_interface.x__ create mode 100644 guile_type_helpers.c delete mode 100644 guile_type_helpers.c__ create mode 100644 guile_type_helpers.h delete mode 100644 guile_type_helpers.h__ diff --git a/guile_interface.h b/guile_interface.h new file mode 100644 index 00000000..91e25a72 --- /dev/null +++ b/guile_interface.h @@ -0,0 +1,15 @@ +#ifndef GUILE_INTERFACE_H +#define GUILE_INTERFACE_H + +#include + +void init_vcomponent (); +void init_vcomponent_type (void); + +SCM make_vcomponent (SCM); +SCM vcomponent_get_attribute (SCM, SCM); +SCM vcomponent_child_count (SCM); +SCM vcomponent_children (SCM); +SCM vcomponent_typeof (SCM); + +#endif /* GUILE_INTERFACE_H */ diff --git a/guile_interface.h__ b/guile_interface.h__ deleted file mode 100644 index 91e25a72..00000000 --- a/guile_interface.h__ +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef GUILE_INTERFACE_H -#define GUILE_INTERFACE_H - -#include - -void init_vcomponent (); -void init_vcomponent_type (void); - -SCM make_vcomponent (SCM); -SCM vcomponent_get_attribute (SCM, SCM); -SCM vcomponent_child_count (SCM); -SCM vcomponent_children (SCM); -SCM vcomponent_typeof (SCM); - -#endif /* GUILE_INTERFACE_H */ diff --git a/guile_interface.scm.c b/guile_interface.scm.c new file mode 100644 index 00000000..a4eb7f8b --- /dev/null +++ b/guile_interface.scm.c @@ -0,0 +1,109 @@ +#include "guile_interface.h" + +#include "vcal.h" +#include "calendar.h" +#include "guile_type_helpers.h" + +static SCM vcomponent_type; + +void init_vcomponent_type (void) { + SCM name = scm_from_utf8_symbol("vcomponent"); + SCM slots = scm_list_1(scm_from_utf8_symbol("data")); + + vcomponent_type = scm_make_foreign_object_type(name, slots, NULL); +} + +SCM_DEFINE (make_vcomponent, "make-vcomponent", 1, 0, 0, + (SCM path), + "Loads a vdir iCalendar from the given path.") +{ + vcomponent* cal = + (vcomponent*) scm_gc_malloc ( + sizeof(*cal), "vcomponent"); + INIT(vcomponent, cal, "ROOT"); + + char* p = scm_to_utf8_stringn(path, NULL); + read_vcalendar(cal, p); + free(p); + + return scm_make_foreign_object_1 + (vcomponent_type, cal); + +} + +/* + * Returns a line from a component. + */ +SCM_DEFINE (vcomponent_get_attribute, "vcomponent-get-attribute", 2, 0, 0, + (SCM calendar, SCM attr), + "Retuns the given attribute from the vevent object at index in calendar.") +{ + scm_assert_foreign_object_type (vcomponent_type, calendar); + vcomponent* cal = scm_foreign_object_ref (calendar, 0); + + char* key = scm_to_utf8_stringn(scm_string_upcase(attr), NULL); + content_line* c = get_property (cal, key); + free(key); + + if (c == NULL) return SCM_BOOL_F; + + SCM llist = SCM_EOL; + FOR (LLIST, content_set, v, &c->val) { + llist = scm_cons(scm_from_strbuf(&v->key), llist); + } + return llist; +} + +SCM_DEFINE (vcomponent_set_attr_x, "vcomponent-set-attribute!", 3, 0, 0, + (SCM component, SCM attr, SCM new_value), + "") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* com = scm_foreign_object_ref (component, 0); + + char* key = scm_to_utf8_stringn(scm_string_upcase(attr), NULL); + content_line* c = get_property (com, key); + free(key); + + c->val.cur->value->key.mem = (char*) new_value; + + + + return SCM_UNSPECIFIED; +} + +SCM_DEFINE (vcomponent_child_count, "vcomponent-child-count", 1, 0, 0, + (SCM component), + "Returns number of child components.") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* c = scm_foreign_object_ref (component, 0); + return scm_from_size_t (SIZE(VECT(vcomponent))(&c->components)); +} + +/* TODO This currently returns a new_ foreign object each time I call it. */ +SCM_DEFINE(vcomponent_children, "vcomponent-children", 1, 0, 0, + (SCM component), + "") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* cal = scm_foreign_object_ref (component, 0); + return scm_from_vector(&cal->components, vcomponent_type); +} + +SCM_DEFINE(vcomponent_typeof, "vcomponent-typeof", 1, 0, 0, + (SCM component), + "Returns type of vcomponent") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* comp = scm_foreign_object_ref (component, 0); + return scm_from_utf8_symbol(comp->type); +} + +void init_vcomponent () { + init_vcomponent_type(); + +#ifndef SCM_MAGIC_SNARFER +#include "guile_interface.x" +#endif +} diff --git a/guile_interface.scm.c__ b/guile_interface.scm.c__ deleted file mode 100644 index e86504be..00000000 --- a/guile_interface.scm.c__ +++ /dev/null @@ -1,91 +0,0 @@ -#include "guile_interface.h" - -#include "vcal.h" -#include "calendar.h" -#include "guile_type_helpers.h" - -static SCM vcomponent_type; - -void init_vcomponent_type (void) { - SCM name = scm_from_utf8_symbol("vcomponent"); - SCM slots = scm_list_1(scm_from_utf8_symbol("data")); - - vcomponent_type = scm_make_foreign_object_type(name, slots, NULL); -} - -SCM_DEFINE (make_vcomponent, "make-vcomponent", 1, 0, 0, - (SCM path), - "Loads a vdir iCalendar from the given path.") -{ - vcomponent* cal = - (vcomponent*) scm_gc_malloc ( - sizeof(*cal), "vcomponent"); - INIT(vcomponent, cal, "ROOT"); - - char* p = scm_to_utf8_stringn(path, NULL); - read_vcalendar(cal, p); - free(p); - - return scm_make_foreign_object_1 - (vcomponent_type, cal); - -} - -/* - * Returns a line from a component. - */ -SCM_DEFINE (vcomponent_get_attribute, "vcomponent-get-attribute", 2, 0, 0, - (SCM calendar, SCM attr), - "Retuns the given attribute from the vevent object at index in calendar.") -{ - scm_assert_foreign_object_type (vcomponent_type, calendar); - vcomponent* cal = scm_foreign_object_ref (calendar, 0); - - char* key = scm_to_utf8_stringn(scm_string_upcase(attr), NULL); - content_line* c = get_property (cal, key); - free(key); - - if (c == NULL) return SCM_BOOL_F; - - SCM llist = SCM_EOL; - FOR (LLIST, content_set, v, &c->val) { - llist = scm_cons(scm_from_strbuf(&v->key), llist); - } - return llist; -} - -SCM_DEFINE (vcomponent_child_count, "vcomponent-child-count", 1, 0, 0, - (SCM component), - "Returns number of child components.") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* c = scm_foreign_object_ref (component, 0); - return scm_from_size_t (SIZE(VECT(vcomponent))(&c->components)); -} - -/* TODO This currently returns a new_ foreign object each time I call it. */ -SCM_DEFINE(vcomponent_children, "vcomponent-children", 1, 0, 0, - (SCM component), - "") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* cal = scm_foreign_object_ref (component, 0); - return scm_from_vector(&cal->components, vcomponent_type); -} - -SCM_DEFINE(vcomponent_typeof, "vcomponent-typeof", 1, 0, 0, - (SCM component), - "Returns type of vcomponent") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* comp = scm_foreign_object_ref (component, 0); - return scm_from_utf8_symbol(comp->type); -} - -void init_vcomponent () { - init_vcomponent_type(); - -#ifndef SCM_MAGIC_SNARFER -#include "guile_interface.x" -#endif -} diff --git a/guile_interface.x__ b/guile_interface.x__ deleted file mode 100644 index badb3ca8..00000000 --- a/guile_interface.x__ +++ /dev/null @@ -1,6 +0,0 @@ -/* cpp arguments: guile_interface.scm.c -std=gnu11 -Wall -Wextra -fPIC -pthread -I/usr/include/guile/2.2 */ -scm_c_define_gsubr (s_make_vcomponent, 1, 0, 0, (scm_t_subr) make_vcomponent);; -scm_c_define_gsubr (s_vcomponent_get_attribute, 2, 0, 0, (scm_t_subr) vcomponent_get_attribute);; -scm_c_define_gsubr (s_vcomponent_child_count, 1, 0, 0, (scm_t_subr) vcomponent_child_count);; -scm_c_define_gsubr (s_vcomponent_children, 1, 0, 0, (scm_t_subr) vcomponent_children);; -scm_c_define_gsubr (s_vcomponent_typeof, 1, 0, 0, (scm_t_subr) vcomponent_typeof);; diff --git a/guile_type_helpers.c b/guile_type_helpers.c new file mode 100644 index 00000000..3f76c2d4 --- /dev/null +++ b/guile_type_helpers.c @@ -0,0 +1,18 @@ +#include "guile_type_helpers.h" + +#include "macro.h" + +SCM scm_from_strbuf(strbuf* s) + { return scm_from_utf8_stringn (s->mem, s->len - 1); } + +SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type) { + SCM l = SCM_EOL; + for (size_t i = 0; i < vect->length; i++) { + l = scm_cons( + scm_make_foreign_object_1 (element_type, GET(VECT(vcomponent))(vect, i)), + l); + } + return scm_reverse(l); +} + + diff --git a/guile_type_helpers.c__ b/guile_type_helpers.c__ deleted file mode 100644 index 3f76c2d4..00000000 --- a/guile_type_helpers.c__ +++ /dev/null @@ -1,18 +0,0 @@ -#include "guile_type_helpers.h" - -#include "macro.h" - -SCM scm_from_strbuf(strbuf* s) - { return scm_from_utf8_stringn (s->mem, s->len - 1); } - -SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type) { - SCM l = SCM_EOL; - for (size_t i = 0; i < vect->length; i++) { - l = scm_cons( - scm_make_foreign_object_1 (element_type, GET(VECT(vcomponent))(vect, i)), - l); - } - return scm_reverse(l); -} - - diff --git a/guile_type_helpers.h b/guile_type_helpers.h new file mode 100644 index 00000000..bb69312d --- /dev/null +++ b/guile_type_helpers.h @@ -0,0 +1,13 @@ +#ifndef GUILE_TYPE_HELPERS_H +#define GUILE_TYPE_HELPERS_H + +#include + +#include "calendar.h" +#include "strbuf.h" + +SCM scm_from_strbuf(strbuf* s); + +SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type); + +#endif /* GUILE_TYPE_HELPERS_H */ diff --git a/guile_type_helpers.h__ b/guile_type_helpers.h__ deleted file mode 100644 index bb69312d..00000000 --- a/guile_type_helpers.h__ +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef GUILE_TYPE_HELPERS_H -#define GUILE_TYPE_HELPERS_H - -#include - -#include "calendar.h" -#include "strbuf.h" - -SCM scm_from_strbuf(strbuf* s); - -SCM scm_from_vector(VECT(vcomponent)* vect, SCM element_type); - -#endif /* GUILE_TYPE_HELPERS_H */ -- cgit v1.2.3