aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-10-01 23:39:00 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-10-01 23:39:00 +0200
commit7539f8c8804849294e100c5442e0397f4f4d2c40 (patch)
tree129fa0bb0f18604bd378724794c855e8e4d230dc
parentStart moving to scheme structs. (diff)
downloadcalp-7539f8c8804849294e100c5442e0397f4f4d2c40.tar.gz
calp-7539f8c8804849294e100c5442e0397f4f4d2c40.tar.xz
Disabled bunch of old stuff, new stuff kinda builds.
-rw-r--r--Makefile2
-rw-r--r--module/vcomponent.scm6
-rw-r--r--module/vcomponent/base.scm24
-rw-r--r--module/vcomponent/primitive.scm30
-rw-r--r--src/calendar.c23
-rw-r--r--src/calendar.h12
-rw-r--r--src/graphs.c.old (renamed from src/graphs.c)0
-rw-r--r--src/graphs.h.old (renamed from src/graphs.h)0
-rw-r--r--src/guile_interface.h.disabled (renamed from src/guile_interface.h)0
-rw-r--r--src/guile_interface.scm.c.disabled (renamed from src/guile_interface.scm.c)0
-rw-r--r--src/guile_type_helpers.c1
-rw-r--r--src/main.c.old (renamed from src/main.c)0
-rw-r--r--src/parse.c43
-rw-r--r--src/parse.h19
-rw-r--r--src/strbuf.c13
-rw-r--r--src/struct.scm.c (renamed from src/struct.c)44
-rw-r--r--src/vcal.c.old (renamed from src/vcal.c)0
-rw-r--r--src/vcal.h.old (renamed from src/vcal.h)0
18 files changed, 119 insertions, 98 deletions
diff --git a/Makefile b/Makefile
index dfd080b8..c8e2fd6f 100644
--- a/Makefile
+++ b/Makefile
@@ -66,7 +66,7 @@ obj/%.scm.go: %.scm $(SO_FILES)
html: $(GO_FILES)
mkdir -p html
ln -sf ../static html
- module/main.scm html -f 2019-07-01 -t 2019-08-30 > html/index.html
+ module/main.scm html -f 2019-10-01 -t 2019-12-31 > html/index.html
tags: $(C_FILES) $(H_FILES)
ctags -R
diff --git a/module/vcomponent.scm b/module/vcomponent.scm
index cc79b646..fc360486 100644
--- a/module/vcomponent.scm
+++ b/module/vcomponent.scm
@@ -1,5 +1,5 @@
(define-module (vcomponent)
- #:use-module ((vcomponent primitive) :select (%vcomponent-make))
+ #:use-module ((vcomponent primitive) :select (parse-path make-vcomponent))
#:use-module (vcomponent datetime)
#:use-module (vcomponent recurrence)
#:use-module (vcomponent timezone)
@@ -81,8 +81,8 @@
(define* (make-vcomponent #:optional path)
(if (not path)
- (%vcomponent-make)
- (let* ((root (%vcomponent-make path))
+ (make-vcomponent)
+ (let* ((root (parse-path path))
(component
(case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type"))
;; == Single ICS file ==
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index fd8628f9..4b49ba66 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -6,11 +6,16 @@
:use-module ((ice-9 optargs) :select (define*-public)))
(define (get-attr component attr)
+ (hash-ref (struct-ref component 3)
+ (as-string attr))
+ #;
(%vcomponent-get-attribute
component
(as-string attr)))
(define (set-attr! component attr value)
+ 'noop
+ #;
(set! (car (get-attr component (as-string attr)))
value))
@@ -49,21 +54,24 @@
(hash-map->list cons (cdar attrptr)))
(define-public type (make-procedure-with-setter
- %vcomponent-get-type
- %vcomponent-set-type!))
-(define-public parent %vcomponent-parent)
-(define-public push-child! %vcomponent-push-child!)
-(define-public (attributes component) (map string->symbol (%vcomponent-attribute-list component)))
+ (lambda (c) (struct-ref c 0))
+ (lambda (c v) struct-set! c 0 v)
+ ))
+(define-public (parent c) (struct-ref c 2))
+(define-public push-child! add-child!)
+(define-public (attributes component) '("noop")
+ #; (map string->symbol (%vcomponent-attribute-list component))
+ )
(define*-public (children component #:optional only-type)
- (let ((childs (%vcomponent-children component)))
+ (let ((childs (slot-ref component 1)))
(if only-type
(filter (lambda (e) (eq? only-type (type e))) childs)
childs)))
-(define-public copy-vcomponent %vcomponent-shallow-copy)
+;; (define-public copy-vcomponent %vcomponent-shallow-copy)
-(define-public filter-children! %vcomponent-filter-children!)
+;; (define-public filter-children! %vcomponent-filter-children!)
(define-public (extract field)
(lambda (e) (attr e field)))
diff --git a/module/vcomponent/primitive.scm b/module/vcomponent/primitive.scm
index ad33a3be..e103feae 100644
--- a/module/vcomponent/primitive.scm
+++ b/module/vcomponent/primitive.scm
@@ -1,19 +1,23 @@
;;; Primitive export of symbols linked from C binary.
(define-module (vcomponent primitive)
- #:export (%vcomponent-children
- %vcomponent-push-child!
- %vcomponent-filter-children!
+ #:export #;
+ (%vcomponent-children ;
+ %vcomponent-push-child! ;
+ %vcomponent-filter-children! ;
+ ;
+ %vcomponent-parent ;
+ ;
+ %vcomponent-make ;
+ %vcomponent-get-type ;
+ %vcomponent-set-type! ;
+ ;
+ %vcomponent-get-attribute ;
+ %vcomponent-attribute-list ;
+ ;
+ %vcomponent-shallow-copy)
- %vcomponent-parent
-
- %vcomponent-make
- %vcomponent-get-type
- %vcomponent-set-type!
-
- %vcomponent-get-attribute
- %vcomponent-attribute-list
-
- %vcomponent-shallow-copy))
+ (make-vcomponent add-line! add-child! make-vline add-attribute! parse-path)
+ )
(load-extension "libguile-calendar" "init_lib")
diff --git a/src/calendar.c b/src/calendar.c
index e634b166..2cd25f13 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -8,11 +8,12 @@
/* basename */
#include <libgen.h>
+#include <libguile.h>
#include "parse.h"
#include "err.h"
-int read_vcalendar(vcomponent* cal, char* path) {
+int read_vcalendar(SCM cal, char* path) {
struct stat statbuf;
if (stat (path, &statbuf) != 0) {
@@ -38,12 +39,12 @@ int read_vcalendar(vcomponent* cal, char* path) {
return 0;
}
-int handle_file(vcomponent* cal, char* path) {
+int handle_file(SCM cal, char* path) {
INFO("Parsing a single file");
/* NAME is the `fancy' name of the calendar. */
- vcomponent_push_val(cal, "NAME", basename(path));
- vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file");
+ // vcomponent_push_val(cal, "NAME", basename(path));
+ // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file");
char* resolved_path = realpath(path, NULL);
open_ics (resolved_path, cal);
free (resolved_path);
@@ -52,7 +53,7 @@ int handle_file(vcomponent* cal, char* path) {
}
-int handle_dir(vcomponent* cal, char* path) {
+int handle_dir(SCM cal, char* path) {
INFO("Parsing a directory");
DIR* dir = opendir(path);
@@ -66,8 +67,8 @@ int handle_dir(vcomponent* cal, char* path) {
/* NAME is the `fancy' name of the calendar. */
- vcomponent_push_val(cal, "NAME", basename(path));
- vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "vdir");
+ // vcomponent_push_val(cal, "NAME", basename(path));
+ // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "vdir");
struct dirent* d;
while ((d = readdir(dir)) != NULL) {
@@ -90,7 +91,8 @@ int handle_dir(vcomponent* cal, char* path) {
info_buf[read - 1] = '\0';
fclose(f);
- vcomponent_push_val(cal, "COLOR", info_buf);
+ // TODO
+ // vcomponent_push_val(cal, "COLOR", info_buf);
} else if (strcmp (d->d_name, "displayname") == 0) {
f = fopen(resolved_path, "r");
read = getline(&info_buf, &size, f);
@@ -104,7 +106,8 @@ int handle_dir(vcomponent* cal, char* path) {
* This works since *currently* values are returned in
* reverse order
*/
- vcomponent_push_val(cal, "NAME", info_buf);
+ // TODO
+ // vcomponent_push_val(cal, "NAME", info_buf);
} else {
open_ics (resolved_path, cal);
}
@@ -149,7 +152,7 @@ int check_ext (const char* path, const char* ext) {
return has_ext && strcmp(buf, ext) == 0;
}
-int open_ics (char* resolved_path, vcomponent* cal) {
+int open_ics (char* resolved_path, SCM cal) {
if (! check_ext(resolved_path, "ics") ) return 2;
FILE* f = fopen(resolved_path, "r");
diff --git a/src/calendar.h b/src/calendar.h
index 20b78a9f..3e6941f9 100644
--- a/src/calendar.h
+++ b/src/calendar.h
@@ -1,7 +1,9 @@
#ifndef CALENDAR_H
#define CALENDAR_H
-#include "vcal.h"
+#include <libguile.h>
+
+// #include "vcal.h"
/*
* Reads all ics flies in path into the given vcomponent. The
@@ -11,7 +13,7 @@
* path should either be a single .ics file (vcalendar), or a
* directory directly containing .ics files (vdir).
*/
-int read_vcalendar(vcomponent* cal, char* path);
+int read_vcalendar(SCM cal, char* path);
/*
* Gets extension from filename. Writes output to ext.
@@ -27,15 +29,15 @@ int get_extension(const char* filename, char* ext, ssize_t max_len);
int check_ext (const char* path, const char* ext);
/* Handle a lone ics file */
-int handle_file(vcomponent* cal, char* path);
+int handle_file(SCM cal, char* path);
/* Handle a directory of ics files */
-int handle_dir(vcomponent* cal, char* path);
+int handle_dir(SCM cal, char* path);
/*
* Helper for opening a single ICS file. Handles file internally, and
* writes output to cal.
*/
-int open_ics (char* resolved_path, vcomponent* cal);
+int open_ics (char* resolved_path, SCM cal);
#endif /* CALENDAR_H */
diff --git a/src/graphs.c b/src/graphs.c.old
index 51a26117..51a26117 100644
--- a/src/graphs.c
+++ b/src/graphs.c.old
diff --git a/src/graphs.h b/src/graphs.h.old
index fe521003..fe521003 100644
--- a/src/graphs.h
+++ b/src/graphs.h.old
diff --git a/src/guile_interface.h b/src/guile_interface.h.disabled
index 76ec24d3..76ec24d3 100644
--- a/src/guile_interface.h
+++ b/src/guile_interface.h.disabled
diff --git a/src/guile_interface.scm.c b/src/guile_interface.scm.c.disabled
index 20c413df..20c413df 100644
--- a/src/guile_interface.scm.c
+++ b/src/guile_interface.scm.c.disabled
diff --git a/src/guile_type_helpers.c b/src/guile_type_helpers.c
index f03ac671..072ddff9 100644
--- a/src/guile_type_helpers.c
+++ b/src/guile_type_helpers.c
@@ -1,5 +1,4 @@
#include "guile_type_helpers.h"
-#include "guile_interface.h"
#include "macro.h"
diff --git a/src/main.c b/src/main.c.old
index 4d8da7d3..4d8da7d3 100644
--- a/src/main.c
+++ b/src/main.c.old
diff --git a/src/parse.c b/src/parse.c
index e79231cb..46f9644e 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -5,7 +5,7 @@
#include <assert.h>
#include "macro.h"
-#include "vcal.h"
+// #include "vcal.h"
#include "err.h"
@@ -17,12 +17,12 @@
// #include "linked_list.inc.h"
// #undef TYPE
-#define T strbuf
-#define V strbuf
-#include "pair.h"
-#include "pair.inc.h"
-#undef T
-#undef V
+// #define T strbuf
+// #define V strbuf
+// #include "pair.h"
+// #include "pair.inc.h"
+// #undef T
+// #undef V
/*
+-------------------------------------------------------+
@@ -47,14 +47,12 @@
/*
* name *(";" param) ":" value CRLF
*/
-int parse_file(char* filename, FILE* f, vcomponent* root) {
- scm_c_use_module ("(vcomponent struct)");
-
+int parse_file(char* filename, FILE* f, SCM root) {
part_context p_ctx = p_key;
SNEW(parse_ctx, ctx, f, filename);
- PUSH(LLIST(vcomponent))(&ctx.comp_stack, root);
+ // PUSH(LLIST(vcomponent))(&ctx.comp_stack, root);
/*
* Create a content_line which we use as storage while we are
@@ -70,11 +68,10 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
// SNEW(strbuf, attr_val);
SNEW(strbuf, str);
- SCM component; /* TODO init to root */
+ SCM component = root;
SCM line = scm_make_vline();
SCM attr_key; /* string */
- SCM line_key; /* string */
- SCM param_set; /* hashtable */
+ SCM line_key = scm_from_utf8_string(""); /* string */
char c;
while ( (c = fgetc(f)) != EOF) {
@@ -103,7 +100,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
* component.
*/
} else {
- scm_set_value_x(line, scm_from_strbuf(&str));
+ scm_struct_set_x(line, vline_value, scm_from_strbuf(&str));
scm_add_line_x(component, line_key, line);
line = scm_make_vline();
}
@@ -140,7 +137,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
* the current parameter set. */
if (p_ctx == p_param_value) {
/* save current parameter value. */
- scm_add_attribute_x(line, line_key, scm_from_strbuf(&str));
+ scm_add_attribute_x(line, attr_key, scm_from_strbuf(&str));
strbuf_soft_reset (&str);
}
@@ -198,9 +195,9 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
FREE(strbuf)(&str);
- assert(POP(LLIST(vcomponent))(&ctx.comp_stack) == root);
- assert(EMPTY(LLIST(strbuf))(&ctx.key_stack));
- assert(EMPTY(LLIST(vcomponent))(&ctx.comp_stack));
+ // assert(POP(LLIST(vcomponent))(&ctx.comp_stack) == root);
+ // assert(EMPTY(LLIST(strbuf))(&ctx.key_stack));
+ // assert(EMPTY(LLIST(vcomponent))(&ctx.comp_stack));
FREE(parse_ctx)(&ctx);
@@ -242,8 +239,8 @@ int fold(parse_ctx* ctx, char c) {
INIT_F(parse_ctx, FILE* f, char* filename) {
- INIT(LLIST(strbuf), &self->key_stack);
- INIT(LLIST(vcomponent), &self->comp_stack);
+ // INIT(LLIST(strbuf), &self->key_stack);
+ // INIT(LLIST(vcomponent), &self->comp_stack);
self->filename = (char*) calloc(sizeof(*filename), strlen(filename) + 1);
strcpy(self->filename, filename);
self->f = f;
@@ -261,8 +258,8 @@ INIT_F(parse_ctx, FILE* f, char* filename) {
FREE_F(parse_ctx) {
- FREE(LLIST(strbuf))(&self->key_stack);
- FREE(LLIST(vcomponent))(&self->comp_stack);
+ // FREE(LLIST(strbuf))(&self->key_stack);
+ // FREE(LLIST(vcomponent))(&self->comp_stack);
free(self->filename);
self->line = 0;
diff --git a/src/parse.h b/src/parse.h
index a7e97ec8..a5169dd7 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -5,7 +5,7 @@
#include <stdlib.h>
#include "strbuf.h"
-#include "vcal.h"
+// #include "vcal.h"
// #define TYPE vcomponent
// #include "linked_list.h"
@@ -51,8 +51,8 @@ typedef struct {
* context stacks used since ICS files form a tree. key_stack is
* only for sequrity purposes.
*/
- LLIST(strbuf) key_stack;
- LLIST(vcomponent) comp_stack;
+ // LLIST(strbuf) key_stack;
+ // LLIST(vcomponent) comp_stack;
/* Number for unfolded lines
* TODO remove this
@@ -82,18 +82,7 @@ FREE_F(parse_ctx);
* Once It has parsed a full line it calls handel_kv. Which build my
* actuall datastructure.
*/
-int parse_file(char* filename, FILE* f, vcomponent* cal);
-
-/*
- * Called whenever parse_file finishes a line. Copies the contents of
- * ctx and the current content_line into the object stack, stored in
- * ctx.
- */
-int handle_kv(
- strbuf* key,
- content_line* cline,
- parse_ctx* ctx
- );
+int parse_file(char* filename, FILE* f, SCM cal);
/*
* Input
diff --git a/src/strbuf.c b/src/strbuf.c
index 66fe2989..1e1365d5 100644
--- a/src/strbuf.c
+++ b/src/strbuf.c
@@ -10,7 +10,6 @@ INIT_F(strbuf) {
self->mem = (char*) calloc(sizeof(*self->mem), self->alloc);
self->ptr = 0;
self->len = 0;
- self->scm = NULL;
return 0;
}
@@ -69,18 +68,6 @@ int DEEP_COPY(strbuf)(strbuf* dest, strbuf* src) {
retval = 1;
}
- if (src->scm != NULL) {
- /*
- * Upon Vcomponent binding into scheme I place all
- * strings inside cons cells. This leads to a deep
- * copy being required. copy-tree however returns
- * the same object for atoms and scheme strings.
- */
- dest->scm = scm_copy_tree(src->scm);
- /* NOTE This is a bit of a leaky abstraction. */
- scm_gc_protect_object(dest->scm);
- }
-
dest->len = src->len;
memcpy(dest->mem, src->mem, src->len);
return retval;
diff --git a/src/struct.c b/src/struct.scm.c
index cd3ee412..abbbba18 100644
--- a/src/struct.c
+++ b/src/struct.scm.c
@@ -2,12 +2,18 @@
#include <libguile.h>
-SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 1, 0, 0,
+SCM vcomponent_vtable;
+SCM vline_vtable;
+
+SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 0, 1, 0,
(SCM type),
"")
{
- SCM str = scm_from_utf8_string("pr" "pw" "pw" "pr");
- SCM vcomponent_vtable = scm_make_vtable(str, SCM_BOOL_F);
+
+ if (SCM_UNBNDP (type)) type = SCM_BOOL_F;
+
+ if (scm_is_false(type)) type = scm_from_utf8_symbol("VIRTUAL");
+
return scm_c_make_struct (vcomponent_vtable, scm_from_int(0),
type, SCM_EOL, SCM_BOOL_F,
scm_make_hash_table(SCM_BOOL_F),
@@ -15,6 +21,18 @@ SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 1, 0, 0,
}
+
+SCM_DEFINE(scm_parse_cal_path, "parse-path", 1, 0, 0,
+ (SCM path),
+ "")
+{
+ SCM root = scm_make_vcomponent(SCM_BOOL_F);
+
+ char* p = scm_to_utf8_stringn(path, NULL);
+ scm_read_vcalendar(root, p);
+ free(p);
+}
+
SCM_DEFINE(scm_add_line_x, "add-line!", 3, 0, 0,
(SCM vcomponent, SCM key, SCM line),
"")
@@ -39,9 +57,6 @@ SCM_DEFINE(scm_add_child_x, "add-child!", 2, 0, 0,
SCM_DEFINE(scm_make_vline, "make-vline", 0, 0, 0,
(), "")
{
- SCM vline_vtable =
- scm_make_vtable(scm_from_utf8_string("pw" "pw"),
- SCM_BOOL_F);
return scm_c_make_struct (vline_vtable, scm_from_int(0),
SCM_BOOL_F, scm_make_hash_table(SCM_BOOL_F),
SCM_UNDEFINED);
@@ -57,3 +72,20 @@ SCM_DEFINE(scm_add_attribute_x, "add-attribute!", 3, 0, 0,
scm_cons(value, scm_hash_ref(table, key, SCM_EOL)));
return SCM_UNSPECIFIED;
}
+
+void init_lib (void) {
+ // init_vcomponent_type();
+ // content_set_lists = scm_make_weak_key_hash_table (scm_from_uint(0x100));
+ SCM str = scm_from_utf8_string("pr" "pw" "pw" "pr");
+ SCM vcomponent_vtable = scm_make_vtable(str, SCM_BOOL_F);
+ scm_set_struct_vtable_name_x (vcomponent_vtable, scm_from_utf8_symbol("vcomponent"));
+
+ SCM vline_vtable =
+ scm_make_vtable(scm_from_utf8_string("pw" "pw"),
+ SCM_BOOL_F);
+ scm_set_struct_vtable_name_x (vline_vtable, scm_from_utf8_symbol("vline"));
+
+#ifndef SCM_MAGIC_SNARFER
+#include "struct.x"
+#endif
+}
diff --git a/src/vcal.c b/src/vcal.c.old
index 29177bf3..29177bf3 100644
--- a/src/vcal.c
+++ b/src/vcal.c.old
diff --git a/src/vcal.h b/src/vcal.h.old
index 2a3ad294..2a3ad294 100644
--- a/src/vcal.h
+++ b/src/vcal.h.old