aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 00:00:47 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 00:05:43 +0100
commit21ef1d9c0db916ed867db46376cce1a0343e2b3f (patch)
tree07efc95f0d89b8935427edb3415c2eb4ca960172
parentRework makefile, made .inc into .inc.h. (diff)
downloadcalp-21ef1d9c0db916ed867db46376cce1a0343e2b3f.tar.gz
calp-21ef1d9c0db916ed867db46376cce1a0343e2b3f.tar.xz
Change Scheme interop in C to use guile-snarf.
-rw-r--r--Makefile9
-rwxr-xr-xcode.scm4
-rw-r--r--scheme.scm.c (renamed from scheme.c)23
3 files changed, 26 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 041f0432..44573805 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,8 @@ H_FILES = $(wildcard *.h)
C_FILES = $(wildcard *.c)
-all: parse libguile-calendar.so
+SCM_C_FILES = $(wildcard *.scm.c)
+X_FILES = $(SCM_C_FILES:.scm.c=.x)
O_FILES = $(addprefix obj/,$(C_FILES:.c=.o))
@@ -26,12 +27,15 @@ parse: $(O_FILES)
$(O_FILES): | $(OBJDIR)
-$(OBJDIR)/%.o : %.c $(H_FILES)
+$(OBJDIR)/%.o : %.c $(H_FILES) $(X_FILES)
$(CC) -c -o $@ $< $(CFLAGS)
$(OBJDIR):
mkdir -p $(OBJDIR)
+%.x : %.scm.c
+ guile-snarf -o $@ $< $(CFLAGS)
+
libguile-calendar.so: $(O_FILES)
$(CC) -shared -o $@ $^ $(LDFLAGS)
@@ -40,3 +44,4 @@ clean:
-rm $(OBJDIR)/*.o
-rmdir $(OBJDIR)
-rm *.so
+ -rm *.x
diff --git a/code.scm b/code.scm
index c00ae90a..c3d5d7b5 100755
--- a/code.scm
+++ b/code.scm
@@ -2,6 +2,8 @@
-s
!#
+(use-modules (ice-9 format))
+
(begin
;; Supurflous begin block here to make sourcing into geiser easier.
(setenv "LD_LIBRARY_PATH" (getcwd))
@@ -11,6 +13,6 @@
(do ((i 0 (1+ i)))
((>= i (calendar-size v)))
(format #t "~3d | ~a~%"
- i (get-attr v i "summary")))
+ i (calendar-get-attr v i "summary")))
diff --git a/scheme.c b/scheme.scm.c
index cacd502e..0d987ffa 100644
--- a/scheme.c
+++ b/scheme.scm.c
@@ -13,8 +13,10 @@ void init_calendar_type (void) {
calendar_type = scm_make_foreign_object_type(name, slots, NULL);
}
-SCM make_calendar (SCM path) {
-
+SCM_DEFINE (make_calendar, "make-calendar", 1, 0, 0,
+ (SCM path),
+ "Loads a vdir iCalendar from the given path.")
+{
vcalendar* cal =
(vcalendar*) scm_gc_malloc (
sizeof(*cal), "calendar");
@@ -33,7 +35,10 @@ static SCM scm_from_strbuf(strbuf* s) {
return scm_from_utf8_stringn (s->mem, s->len);
}
-SCM calendar_get_attr(SCM calendar, SCM id, SCM attr) {
+SCM_DEFINE (calendar_get_attr, "calendar-get-attr", 3, 0, 0,
+ (SCM calendar, SCM id, SCM attr),
+ "Retuns the given attribute from the vevent object at index in calendar.")
+{
scm_assert_foreign_object_type (calendar_type, calendar);
vcalendar* cal = scm_foreign_object_ref (calendar, 0);
@@ -47,7 +52,10 @@ SCM calendar_get_attr(SCM calendar, SCM id, SCM attr) {
return scm_from_strbuf(&c->val);
}
-SCM number_events(SCM calendar) {
+SCM_DEFINE (calendar_size, "calendar-size", 1, 0, 0,
+ (SCM calendar),
+ "Returns number of events in a vcalendar.")
+{
scm_assert_foreign_object_type (calendar_type, calendar);
vcalendar* cal = scm_foreign_object_ref (calendar, 0);
return scm_from_size_t (cal->n_events);
@@ -56,7 +64,8 @@ SCM number_events(SCM calendar) {
void init_calendar () {
init_calendar_type();
- scm_c_define_gsubr ("make-calendar", 1, 0, 0, make_calendar);
- scm_c_define_gsubr ("get-attr", 3, 0, 0, calendar_get_attr);
- scm_c_define_gsubr ("calendar-size", 1, 0, 0, number_events);
+#ifndef SCM_MAGIC_SNARFER
+#include "scheme.x"
+#endif
+
}