aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-10-02 23:11:56 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-10-02 23:11:56 +0200
commite940c6e74114830fb41c061035b5a160e0c3b6ab (patch)
tree1985b5895e3d8a0c28a44fcdffa0e17ec15f267f
parentMade parser work again (for single files). (diff)
downloadcalp-e940c6e74114830fb41c061035b5a160e0c3b6ab.tar.gz
calp-e940c6e74114830fb41c061035b5a160e0c3b6ab.tar.xz
Restore directory parsing.
-rw-r--r--src/parse.c20
-rw-r--r--src/struct.scm.c12
2 files changed, 13 insertions, 19 deletions
diff --git a/src/parse.c b/src/parse.c
index 0e243234..dd8066ed 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -73,15 +73,15 @@ int parse_file(char* filename, FILE* f, SCM root) {
SCM attr_key; /* string */
SCM line_key = scm_from_utf8_string(""); /* string */
- INFO("Starting parsing");
+ INFO_F("Parsing [%s]", filename);
+
char c;
- INFO("here");
while ( (c = fgetc(f)) != EOF) {
- INFO_F("LOOP %c", c);
+ // INFO_F("LOOP %c", c);
/* We have a linebreak */
if (c == '\r' || c == '\n') {
- INFO("EOL");
+ // INFO("EOL");
if (fold(&ctx, c) > 0) {
/* Actuall end of line, handle value */
@@ -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,7 @@ int parse_file(char* filename, FILE* f, SCM root) {
* component.
*/
} else {
- INFO("Adding attribute");
+ // INFO("Adding attribute");
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 +127,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("Param key");
attr_key = scm_from_strbuf(&str);
p_ctx = p_param_value;
strbuf_soft_reset (&str);
@@ -144,7 +144,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("param value");
/* save current parameter value. */
scm_add_attribute_x(line, attr_key, scm_from_strbuf(&str));
strbuf_soft_reset (&str);
@@ -158,7 +158,7 @@ int parse_file(char* filename, FILE* f, SCM root) {
*/
if (p_ctx == p_key) {
- INFO("key");
+ // INFO("key");
// TRANSFER(&cline_key, &ctx.str);
// NEW(content_set, p);
diff --git a/src/struct.scm.c b/src/struct.scm.c
index b5aa09c1..9b11696d 100644
--- a/src/struct.scm.c
+++ b/src/struct.scm.c
@@ -3,6 +3,7 @@
#include <libguile.h>
#include "parse.h"
+#include "calendar.h"
SCM vcomponent_vtable;
SCM vline_vtable;
@@ -12,10 +13,9 @@ SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 0, 1, 0,
"")
{
- if (SCM_UNBNDP (type))
+ if (SCM_UNBNDP (type) || scm_is_false (type))
type = scm_from_utf8_symbol("VIRTUAL");
- /* This segfaults */
return scm_make_struct_no_tail
(vcomponent_vtable,
scm_list_4(type, SCM_EOL, SCM_BOOL_F,
@@ -31,13 +31,7 @@ SCM_DEFINE(scm_parse_cal_path, "parse-cal-path", 1, 0, 0,
SCM root = scm_make_vcomponent(SCM_UNSPECIFIED);
char* p = scm_to_utf8_stringn(path, NULL);
- // scm_read_vcalendar(root, p);
- /* TODO check that path is good? */
- printf("Parsing [%s]\n", p);
- FILE* f = fopen(p, "r");
- printf("FILE = %p\n", f);
- parse_file (p, f, root);
- /* TODO free file */
+ read_vcalendar(root, p);
free(p);
return root;