aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-10-03 00:46:01 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-10-03 00:46:01 +0200
commite13f6bb201dff690208b9cc951b5c098b0d63356 (patch)
tree7497e7f8e367ca9cde3aaf588f65f69d31106721
parentRestore directory parsing. (diff)
downloadcalp-e13f6bb201dff690208b9cc951b5c098b0d63356.tar.gz
calp-e13f6bb201dff690208b9cc951b5c098b0d63356.tar.xz
Slowly going through and fixing everything.
-rw-r--r--module/vcomponent.scm113
-rw-r--r--module/vcomponent/base.scm32
-rw-r--r--src/calendar.c9
-rw-r--r--src/parse.c15
4 files changed, 92 insertions, 77 deletions
diff --git a/module/vcomponent.scm b/module/vcomponent.scm
index a106d993..93449c4b 100644
--- a/module/vcomponent.scm
+++ b/module/vcomponent.scm
@@ -82,59 +82,60 @@
(define* (make-vcomponent #:optional path)
(if (not path)
(make-vcomponent)
- (let* ((root (parse-cal-path path))
- (component
- (case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type"))
- ;; == Single ICS file ==
- ;; Remove the abstract ROOT component,
- ;; returning the wanted VCALENDAR component
- ((file)
- ;; TODO test this when an empty file is given.
- (car (children root)))
-
- ;; == Assume vdir ==
- ;; Also removes the abstract ROOT component, but also
- ;; merges all VCALENDAR's children into the a newly
- ;; created VCALENDAR component, and return that component.
- ;;
- ;; TODO the other VCALENDAR components might not get thrown away,
- ;; this since I protect them from the GC in the C code.
- ((vdir)
- (let ((accum (make-vcomponent))
- (ch (children root)))
- (set! (type accum) "VCALENDAR")
-
- (unless (null? ch)
- (for key in (attributes (car ch))
- (set! (attr accum key) (attr (car ch) key))))
-
- (for cal in ch
- (for component in (children cal)
- (case (type component)
- ((VTIMEZONE)
- (unless (find (lambda (z)
- (string=? (attr z "TZID")
- (attr component "TZID")))
- (children accum 'VTIMEZONE))
- (push-child! accum component)))
- (else (push-child! accum component)))))
- ;; return
- accum))
-
- ((no-type) (throw 'no-type))
-
- (else (throw 'something)))))
-
- (parse-dates! component)
-
- (unless (attr component "NAME")
- (set! (attr component "NAME")
- (or (attr component "X-WR-CALNAME")
- (attr root "NAME"))))
-
- (unless (attr component "COLOR")
- (set! (attr component "COLOR")
- (attr root "COLOR")))
-
- ;; return
- component)))
+ (let ((root (parse-cal-path path)))
+ (format #t "root = ~a~%" root )
+ (let* ((component
+ (case (string->symbol (or (attr root "X-HNH-SOURCETYPE") "no-type"))
+ ;; == Single ICS file ==
+ ;; Remove the abstract ROOT component,
+ ;; returning the wanted VCALENDAR component
+ ((file)
+ ;; TODO test this when an empty file is given.
+ (display "Hello\n")
+ (car (children root)))
+
+ ;; == Assume vdir ==
+ ;; Also removes the abstract ROOT component, but also
+ ;; merges all VCALENDAR's children into the a newly
+ ;; created VCALENDAR component, and return that component.
+ ;;
+ ;; TODO the other VCALENDAR components might not get thrown away,
+ ;; this since I protect them from the GC in the C code.
+ ((vdir)
+ (let ((accum (make-vcomponent))
+ (ch (children root)))
+ (set! (type accum) "VCALENDAR")
+
+ (unless (null? ch)
+ (for key in (attributes (car ch))
+ (set! (attr accum key) (attr (car ch) key))))
+
+ (for cal in ch
+ (for component in (children cal)
+ (case (type component)
+ ((VTIMEZONE)
+ (unless (find (lambda (z)
+ (string=? (attr z "TZID")
+ (attr component "TZID")))
+ (children accum 'VTIMEZONE))
+ (push-child! accum component)))
+ (else (push-child! accum component)))))
+ ;; return
+ accum))
+
+ ((no-type) (throw 'no-type)))))
+
+ (display "Here?\n")
+ (parse-dates! component)
+
+ (unless (attr component "NAME")
+ (set! (attr component "NAME")
+ (or (attr component "X-WR-CALNAME")
+ (attr root "NAME"))))
+
+ (unless (attr component "COLOR")
+ (set! (attr component "COLOR")
+ (attr root "COLOR")))
+
+ ;; return
+ component))))
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index 4b49ba66..395c2d9c 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -6,8 +6,9 @@
:use-module ((ice-9 optargs) :select (define*-public)))
(define (get-attr component attr)
- (hash-ref (struct-ref component 3)
- (as-string attr))
+ (and=> (hash-ref (struct-ref component 3)
+ (as-string attr))
+ (lambda (l) (struct-ref l 0)))
#;
(%vcomponent-get-attribute
component
@@ -19,26 +20,29 @@
(set! (car (get-attr component (as-string attr)))
value))
-(define-public value caar)
+;; (define-public value caar)
-(define-public (values-left-count attr-list)
- (length (take-while identity attr-list)))
+;; (define-public (values-left-count attr-list)
+;; (length (take-while identity attr-list)))
-(define-public (value-count attr-list)
- (length (take-while identity (cdr (drop-while identity attr-list)))))
+;; (define-public (value-count attr-list)
+;; (length (take-while identity (cdr (drop-while identity attr-list)))))
(define-public attr* get-attr)
-(define (get-first c a)
- (and=> (car (get-attr c a)) car))
+;; (define (get-first c a)
+;; (and=> (car (get-attr c a)) car))
-(define (set-first! c a v)
- (and=> (car (get-attr c a))
- (lambda (f) (set! (car f) v))))
+;; (define (set-first! c a v)
+;; (and=> (car (get-attr c a))
+;; (lambda (f) (set! (car f) v))))
(define-public attr
(make-procedure-with-setter
- get-first set-first!))
+; get-first set-first!
+ get-attr
+ set-attr!
+ ))
(define-public prop
@@ -64,7 +68,7 @@
)
(define*-public (children component #:optional only-type)
- (let ((childs (slot-ref component 1)))
+ (let ((childs (struct-ref component 1)))
(if only-type
(filter (lambda (e) (eq? only-type (type e))) childs)
childs)))
diff --git a/src/calendar.c b/src/calendar.c
index 2cd25f13..a90dfe44 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -10,6 +10,8 @@
#include <libgen.h>
#include <libguile.h>
+#include "struct.h"
+
#include "parse.h"
#include "err.h"
@@ -45,6 +47,9 @@ int handle_file(SCM 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", "file");
+ SCM line = scm_make_vline();
+ scm_struct_set_x(line, vline_value, scm_from_utf8_string("file"));
+ scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line);
char* resolved_path = realpath(path, NULL);
open_ics (resolved_path, cal);
free (resolved_path);
@@ -68,7 +73,9 @@ int handle_dir(SCM 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");
+ SCM line = scm_make_vline();
+ scm_struct_set_x(line, vline_value, scm_from_utf8_string("vdir"));
+ scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line);
struct dirent* d;
while ((d = readdir(dir)) != NULL) {
diff --git a/src/parse.c b/src/parse.c
index dd8066ed..06d8707c 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -91,14 +91,14 @@ int parse_file(char* filename, FILE* f, SCM root) {
*/
if (string_eq(line_key, scm_from_utf8_string("BEGIN"))) {
/* key \in { VCALENDAR, VEVENT, VALARM, VTODO, VTIMEZONE, ... } */
- // INFO("Creating child");
+ INFO("Creating child");
SCM child = scm_make_vcomponent(scm_string_to_symbol(scm_from_strbuf(&str)));
scm_add_child_x (component, child);
component = child;
} else if (string_eq(line_key, scm_from_utf8_string("END"))) {
// TODO make current component be parent of current component?
- // INFO("back to parent");
+ INFO("back to parent");
component = scm_component_parent(component);
/*
@@ -106,7 +106,8 @@ int parse_file(char* filename, FILE* f, SCM root) {
* component.
*/
} else {
- // INFO("Adding attribute");
+ strbuf_cap(&str); // TODO remove
+ INFO_F("Adding attribute [%s]", str.mem);
scm_struct_set_x(line, vline_value, scm_from_strbuf(&str));
scm_add_line_x(component, line_key, line);
line = scm_make_vline();
@@ -127,7 +128,7 @@ int parse_file(char* filename, FILE* f, SCM root) {
/* Save the current parameter key */
// TODO
// TRANSFER (&param_key, &ctx.str);
- // INFO("Param key");
+ INFO_F("Param key [%s]", str.mem);
attr_key = scm_from_strbuf(&str);
p_ctx = p_param_value;
strbuf_soft_reset (&str);
@@ -144,7 +145,7 @@ int parse_file(char* filename, FILE* f, SCM root) {
/* We got a parameter value, push the current string to
* the current parameter set. */
if (p_ctx == p_param_value) {
- // INFO("param value");
+ INFO_F("param value [%s]", str.mem);
/* save current parameter value. */
scm_add_attribute_x(line, attr_key, scm_from_strbuf(&str));
strbuf_soft_reset (&str);
@@ -158,7 +159,8 @@ int parse_file(char* filename, FILE* f, SCM root) {
*/
if (p_ctx == p_key) {
- // INFO("key");
+ strbuf_cap(&str); // TODO remove
+ INFO_F("key [%s]", str.mem);
// TRANSFER(&cline_key, &ctx.str);
// NEW(content_set, p);
@@ -193,6 +195,7 @@ int parse_file(char* filename, FILE* f, SCM root) {
* end with CRLF. My files however does not, so we also parse
* the end here.
*/
+ ERR("Not implemented");
// TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str);
// TODO