From 7539f8c8804849294e100c5442e0397f4f4d2c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 1 Oct 2019 23:39:00 +0200 Subject: Disabled bunch of old stuff, new stuff kinda builds. --- Makefile | 2 +- module/vcomponent.scm | 6 +- module/vcomponent/base.scm | 24 ++-- module/vcomponent/primitive.scm | 30 +++-- src/calendar.c | 23 ++-- src/calendar.h | 12 +- src/graphs.c | 144 -------------------- src/graphs.c.old | 144 ++++++++++++++++++++ src/graphs.h | 15 --- src/graphs.h.old | 15 +++ src/guile_interface.h | 28 ---- src/guile_interface.h.disabled | 28 ++++ src/guile_interface.scm.c | 261 ------------------------------------- src/guile_interface.scm.c.disabled | 261 +++++++++++++++++++++++++++++++++++++ src/guile_type_helpers.c | 1 - src/main.c | 120 ----------------- src/main.c.old | 120 +++++++++++++++++ src/parse.c | 43 +++--- src/parse.h | 19 +-- src/strbuf.c | 13 -- src/struct.c | 59 --------- src/struct.scm.c | 91 +++++++++++++ src/vcal.c | 175 ------------------------- src/vcal.c.old | 175 +++++++++++++++++++++++++ src/vcal.h | 120 ----------------- src/vcal.h.old | 120 +++++++++++++++++ 26 files changed, 1035 insertions(+), 1014 deletions(-) delete mode 100644 src/graphs.c create mode 100644 src/graphs.c.old delete mode 100644 src/graphs.h create mode 100644 src/graphs.h.old delete mode 100644 src/guile_interface.h create mode 100644 src/guile_interface.h.disabled delete mode 100644 src/guile_interface.scm.c create mode 100644 src/guile_interface.scm.c.disabled delete mode 100644 src/main.c create mode 100644 src/main.c.old delete mode 100644 src/struct.c create mode 100644 src/struct.scm.c delete mode 100644 src/vcal.c create mode 100644 src/vcal.c.old delete mode 100644 src/vcal.h create mode 100644 src/vcal.h.old 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 +#include #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 + +// #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 deleted file mode 100644 index 51a26117..00000000 --- a/src/graphs.c +++ /dev/null @@ -1,144 +0,0 @@ -#include "graphs.h" - -#include -#include -#include -#include "err.h" - -// #define TYPE strbuf -// #include "linked_list.h" -// #include "linked_list.inc.h" -// #undef TYPE - -int create_graph_trie (vcomponent* ev, char* filename) { - FILE* f = fopen(filename, "w"); - - fputs("digraph {\n rankdir=LR;", f); - trie_to_dot(&ev->clines, f); - fputs("}", f); - - fclose(f); - - INFO_F("Wrote '%s' to '%s'", vcomponent_get_val(ev, "X-HNH-FILENAME"), filename); - - return 0; -} - -int helper_vcomponent (vcomponent* root, FILE* f) { - fprintf(f, "subgraph \"cluster_root\" { label=File; \"%p\" [label=%s] }\n", root, root->type); - - TRIE(content_line)* trie = &root->clines; - TRIE_NODE(content_line)* n = trie->root->child; - - if (! EMPTY(TRIE(content_line))(trie)) { - fprintf(f, "subgraph \"cluster_%p\" {\n", root); - fprintf(f, "\"%p\" [label=trie fontcolor=gray, color=gray];", trie); - fprintf(f, "\"%p\" -> \"%p\" [color=red]\n", root, trie); - while (n != NULL) { - fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", - (void*) trie, - (void*) n); - fprintf(f, "subgraph \"cluster_%c_%p\" {\ncolor=red; \n", - n->c, root); - trie_to_dot_helper( n, f ); - - - fputs("}", f); - n = n->next; - } - fputs("}", f); - } - - FOR(LLIST, vcomponent, child, &root->components) { - fprintf(f, "\"%p\" -> \"%p\"\n", root, child); - helper_vcomponent(child, f); - } - return 0; -} - -int create_graph_vcomponent (vcomponent* root, char* outfile) { - FILE* f = fopen(outfile, "w"); - if (f == NULL) { - ERR_F("Error opening file %s, errno = %i", outfile, errno); - return 1; - } - vcomponent* c = root; - fputs("digraph {", f); - helper_vcomponent(c, f); - fputs("}", f); - fclose(f); - return 0; -} - -#define T content_line - -int trie_to_dot ( TRIE(T)* trie, FILE* f ) { - TRIE_NODE(T)* n = trie->root->child; - fprintf(f, "\"%p\" [label=root fontcolor=gray, color=gray];", trie); - while (n != NULL) { - fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", - (void*) trie, - (void*) n); - fprintf(f, "subgraph \"cluster_%c\" {\n", - n->c); - trie_to_dot_helper( n, f ); - fputs("}", f); - n = n->next; - } - return 0; -} - -int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { - if (L(root) == NULL) { - fprintf(f, "\"%p\"[label = \"%c\" style=filled fillcolor=white];\n", - (void*) root, root->c); - } else { - fprintf(f, "\"%p\"[label = \"%c [%i]\" style=filled fillcolor=green];\n", - (void*) root, root->c, - SIZE(LLIST(content_set))(L(root)) - ); - } - TRIE_NODE(T)* child = root->child; - - // ---------------------------------------- -#if 1 /* Toggle values */ - if (L(root) != NULL) { - - FOR(LLIST, content_set, v, L(root)) { - char buf[0x100]; - FMT(strbuf)(&v->key, buf); - fprintf(f, "\"%p\" [label=\"%s\" shape=rectangle color=darkgreen];\n", - v, buf); - /* Edge between TRIE char node and data node */ - fprintf(f, "\"%p\" -> \"%p\";\n", root, v); - - /* Parameters */ - LLIST(strbuf)* keys = KEYS(TRIE(param_set))(&v->val); - FOR(LLIST, strbuf, key, keys) { - param_set* p = GET(TRIE(param_set))(&v->val, key->mem); - - fprintf(f, "\"%p\" [label=\"%s\" color=blue];\n", - key, key->mem); - /* Edge between data node and param key node */ - fprintf(f, "\"%p\" -> \"%p\";", v, key); - - FOR(LLIST, strbuf, str, p) { - fprintf(f, "\"%p\" [label=\"%s\" color=orange];", - str, str->mem); - /* Edge between param key node and param value node */ - fprintf(f, "\"%p\" -> \"%p\";", key, str); - } - } - } - } -#endif - // ---------------------------------------- - - while (child != NULL) { - fprintf(f, "\"%p\" -> \"%p\";\n", - (void*) root, (void*) child); - trie_to_dot_helper(child, f); - child = child->next; - } - return 0; -} diff --git a/src/graphs.c.old b/src/graphs.c.old new file mode 100644 index 00000000..51a26117 --- /dev/null +++ b/src/graphs.c.old @@ -0,0 +1,144 @@ +#include "graphs.h" + +#include +#include +#include +#include "err.h" + +// #define TYPE strbuf +// #include "linked_list.h" +// #include "linked_list.inc.h" +// #undef TYPE + +int create_graph_trie (vcomponent* ev, char* filename) { + FILE* f = fopen(filename, "w"); + + fputs("digraph {\n rankdir=LR;", f); + trie_to_dot(&ev->clines, f); + fputs("}", f); + + fclose(f); + + INFO_F("Wrote '%s' to '%s'", vcomponent_get_val(ev, "X-HNH-FILENAME"), filename); + + return 0; +} + +int helper_vcomponent (vcomponent* root, FILE* f) { + fprintf(f, "subgraph \"cluster_root\" { label=File; \"%p\" [label=%s] }\n", root, root->type); + + TRIE(content_line)* trie = &root->clines; + TRIE_NODE(content_line)* n = trie->root->child; + + if (! EMPTY(TRIE(content_line))(trie)) { + fprintf(f, "subgraph \"cluster_%p\" {\n", root); + fprintf(f, "\"%p\" [label=trie fontcolor=gray, color=gray];", trie); + fprintf(f, "\"%p\" -> \"%p\" [color=red]\n", root, trie); + while (n != NULL) { + fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", + (void*) trie, + (void*) n); + fprintf(f, "subgraph \"cluster_%c_%p\" {\ncolor=red; \n", + n->c, root); + trie_to_dot_helper( n, f ); + + + fputs("}", f); + n = n->next; + } + fputs("}", f); + } + + FOR(LLIST, vcomponent, child, &root->components) { + fprintf(f, "\"%p\" -> \"%p\"\n", root, child); + helper_vcomponent(child, f); + } + return 0; +} + +int create_graph_vcomponent (vcomponent* root, char* outfile) { + FILE* f = fopen(outfile, "w"); + if (f == NULL) { + ERR_F("Error opening file %s, errno = %i", outfile, errno); + return 1; + } + vcomponent* c = root; + fputs("digraph {", f); + helper_vcomponent(c, f); + fputs("}", f); + fclose(f); + return 0; +} + +#define T content_line + +int trie_to_dot ( TRIE(T)* trie, FILE* f ) { + TRIE_NODE(T)* n = trie->root->child; + fprintf(f, "\"%p\" [label=root fontcolor=gray, color=gray];", trie); + while (n != NULL) { + fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", + (void*) trie, + (void*) n); + fprintf(f, "subgraph \"cluster_%c\" {\n", + n->c); + trie_to_dot_helper( n, f ); + fputs("}", f); + n = n->next; + } + return 0; +} + +int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { + if (L(root) == NULL) { + fprintf(f, "\"%p\"[label = \"%c\" style=filled fillcolor=white];\n", + (void*) root, root->c); + } else { + fprintf(f, "\"%p\"[label = \"%c [%i]\" style=filled fillcolor=green];\n", + (void*) root, root->c, + SIZE(LLIST(content_set))(L(root)) + ); + } + TRIE_NODE(T)* child = root->child; + + // ---------------------------------------- +#if 1 /* Toggle values */ + if (L(root) != NULL) { + + FOR(LLIST, content_set, v, L(root)) { + char buf[0x100]; + FMT(strbuf)(&v->key, buf); + fprintf(f, "\"%p\" [label=\"%s\" shape=rectangle color=darkgreen];\n", + v, buf); + /* Edge between TRIE char node and data node */ + fprintf(f, "\"%p\" -> \"%p\";\n", root, v); + + /* Parameters */ + LLIST(strbuf)* keys = KEYS(TRIE(param_set))(&v->val); + FOR(LLIST, strbuf, key, keys) { + param_set* p = GET(TRIE(param_set))(&v->val, key->mem); + + fprintf(f, "\"%p\" [label=\"%s\" color=blue];\n", + key, key->mem); + /* Edge between data node and param key node */ + fprintf(f, "\"%p\" -> \"%p\";", v, key); + + FOR(LLIST, strbuf, str, p) { + fprintf(f, "\"%p\" [label=\"%s\" color=orange];", + str, str->mem); + /* Edge between param key node and param value node */ + fprintf(f, "\"%p\" -> \"%p\";", key, str); + } + } + } + } +#endif + // ---------------------------------------- + + while (child != NULL) { + fprintf(f, "\"%p\" -> \"%p\";\n", + (void*) root, (void*) child); + trie_to_dot_helper(child, f); + child = child->next; + } + return 0; +} diff --git a/src/graphs.h b/src/graphs.h deleted file mode 100644 index fe521003..00000000 --- a/src/graphs.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef GRAPHS_H -#define GRAPHS_H - -#include "vcal.h" - -int create_graph_trie (vcomponent* ev, char* filename); - -int create_graph_vcomponent (vcomponent* root, char* outfile); - -int helper_vcomponent (vcomponent* root, FILE* f); - -int trie_to_dot ( TRIE(content_line)*, FILE* ); -int trie_to_dot_helper ( TRIE_NODE(content_line)*, FILE* ); - -#endif /* GRAPHS_H */ diff --git a/src/graphs.h.old b/src/graphs.h.old new file mode 100644 index 00000000..fe521003 --- /dev/null +++ b/src/graphs.h.old @@ -0,0 +1,15 @@ +#ifndef GRAPHS_H +#define GRAPHS_H + +#include "vcal.h" + +int create_graph_trie (vcomponent* ev, char* filename); + +int create_graph_vcomponent (vcomponent* root, char* outfile); + +int helper_vcomponent (vcomponent* root, FILE* f); + +int trie_to_dot ( TRIE(content_line)*, FILE* ); +int trie_to_dot_helper ( TRIE_NODE(content_line)*, FILE* ); + +#endif /* GRAPHS_H */ diff --git a/src/guile_interface.h b/src/guile_interface.h deleted file mode 100644 index 76ec24d3..00000000 --- a/src/guile_interface.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GUILE_INTERFACE_H -#define GUILE_INTERFACE_H - -#include -#include "vcal.h" - -/* - * At a number of places scm_gc_{un,}protect_object is called. - * This is needed since most of my structures are allocated with the - * regular malloc, instead of the scm_gc_malloc variants. - * This leads to the garbage collector not realizing that I still have - * the components, and deletes them. - * - * The protection markers stop the GC from doing its thing. - */ - -void init_lib (void); -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); - -SCM scm_from_vcomponent (vcomponent*); - -#endif /* GUILE_INTERFACE_H */ diff --git a/src/guile_interface.h.disabled b/src/guile_interface.h.disabled new file mode 100644 index 00000000..76ec24d3 --- /dev/null +++ b/src/guile_interface.h.disabled @@ -0,0 +1,28 @@ +#ifndef GUILE_INTERFACE_H +#define GUILE_INTERFACE_H + +#include +#include "vcal.h" + +/* + * At a number of places scm_gc_{un,}protect_object is called. + * This is needed since most of my structures are allocated with the + * regular malloc, instead of the scm_gc_malloc variants. + * This leads to the garbage collector not realizing that I still have + * the components, and deletes them. + * + * The protection markers stop the GC from doing its thing. + */ + +void init_lib (void); +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); + +SCM scm_from_vcomponent (vcomponent*); + +#endif /* GUILE_INTERFACE_H */ diff --git a/src/guile_interface.scm.c b/src/guile_interface.scm.c deleted file mode 100644 index 20c413df..00000000 --- a/src/guile_interface.scm.c +++ /dev/null @@ -1,261 +0,0 @@ -#include "guile_interface.h" - -#include "calendar.h" -#include "guile_type_helpers.h" - -static SCM vcomponent_type; -static SCM content_set_lists; - -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, "%vcomponent-make", 0, 1, 0, - (SCM path), - "Loads a vdir iCalendar from the given path.") -{ - vcomponent* cal = - (vcomponent*) scm_gc_malloc ( - sizeof(*cal), "vcomponent"); - - if (SCM_UNBNDP(path)) { - INIT(vcomponent, cal); - } else { - INIT(vcomponent, cal, "ROOT"); - - char* p = scm_to_utf8_stringn(path, NULL); - read_vcalendar(cal, p); - free(p); - } - - return scm_from_vcomponent (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); - - const char* key = scm_i_string_chars (attr); - content_line* c = get_attributes (cal, key); - - if (c == NULL) { - vcomponent_push_val(cal, key, ""); - c = get_attributes (cal, key); - c->cval->key.scm = SCM_BOOL_F; - } - - SCM ptr = scm_from_pointer(c, NULL); - SCM ret = scm_hashq_ref (content_set_lists, ptr, SCM_BOOL_F); - if (! scm_is_false (ret)) { - return ret; - } - - SCM val, proplist; - SCM attrroot = scm_list_1(SCM_BOOL_F); - SCM attrlist = attrroot; - LLIST(strbuf) *triekeys, *trievals; - - /* For every instance of a line */ - FOR (LLIST, content_set, v, c) { - val = scm_from_strbuf(&v->key); - - if (! scm_is_pair(val)) { - // TODO look into using a weak hash table instead - - // TODO why is it an error to unprotect the object here? - // scm_from_strbuf should already have protected it... - // scm_gc_unprotect_object(v->key.scm); - SCM htable = scm_make_hash_table (scm_from_ulong(32)); - val = scm_cons(val, htable); - v->key.scm = val; - scm_gc_protect_object(v->key.scm); - - triekeys = KEYS(TRIE(param_set))(&v->val); - /* For every property key bound to the current attribute */ - FOR (LLIST, strbuf, k, triekeys) { - proplist = SCM_EOL; - - trievals = GET(TRIE(param_set))(&v->val, k->mem); - /* For every value bound to the current property */ - FOR (LLIST, strbuf, s, trievals) { - proplist = scm_cons(scm_from_strbuf(s), proplist); - } - - scm_hashq_set_x(htable, scm_from_strbuf_symbol(k), - scm_reverse(proplist)); - } - } - - attrlist = scm_cons(val, attrlist); - } - - /* create circular list */ - scm_set_cdr_x (attrroot, attrlist); - - - scm_hashq_set_x (content_set_lists, ptr, attrlist); - - return attrlist; -} - -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(LLIST(vcomponent))(&c->components)); -} - -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); - - SCM llist = SCM_EOL; - FOR (LLIST, vcomponent, v, &cal->components) { - llist = scm_cons(scm_from_vcomponent(v), llist); - } - return llist; -} - -SCM_DEFINE(vcomponent_filter_children_x, "%vcomponent-filter-children!", - 2, 0, 0, - (SCM pred, SCM component), - "Remove all children from component who DOESN'T satisfy `pred`") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* cal = scm_foreign_object_ref (component, 0); - - for (LINK(vcomponent)* l = FIRST(&cal->components); - l->after != NULL; - l = l->after) - { - if (scm_is_false(scm_call_1 (pred, scm_from_vcomponent(l->value)))) { - FFREE(vcomponent, l->value); - UNLINK(LINK(vcomponent))(l); - } - } - - return SCM_UNSPECIFIED; -} - -SCM_DEFINE(vcomponent_push_child_x, "%vcomponent-push-child!", 2, 0, 0, - (SCM component, SCM child), - "") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - scm_assert_foreign_object_type (vcomponent_type, child); - vcomponent* comp = scm_foreign_object_ref (component, 0); - vcomponent* chil = scm_foreign_object_ref (child, 0); - - PUSH(vcomponent)(comp, chil); - - return SCM_UNSPECIFIED; -} - -SCM_DEFINE (vcomponent_parent, "%vcomponent-parent", 1, 0, 0, - (SCM component), - "") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* comp = scm_foreign_object_ref (component, 0); - - vcomponent* parent = comp->parent; - if (strcmp(parent->type, "ROOT") == 0) { - return SCM_BOOL_F; - } else { - return scm_from_vcomponent(parent); - } -} - -SCM_DEFINE(vcomponent_typeof, "%vcomponent-get-type", 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); - - if (comp->scmtype == NULL) { - comp->scmtype = scm_from_utf8_symbol(comp->type); - } - - return comp->scmtype; -} - -SCM_DEFINE(vcomponent_set_type_x, "%vcomponent-set-type!", 2, 0, 0, - (SCM component, SCM type), - "Replace current type of vcomponent") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* comp = scm_foreign_object_ref (component, 0); - - if (comp->type) free (comp->type); - - char* ntype = scm_to_utf8_stringn (type, NULL); - comp->type = calloc(sizeof(*ntype), strlen(ntype) + 1); - strcpy(comp->type, ntype); - - return SCM_UNSPECIFIED; -} - -SCM scm_from_vcomponent(vcomponent* v) { - if (v->scm == NULL) { - v->scm = scm_make_foreign_object_1 (vcomponent_type, v); - scm_gc_protect_object(v->scm); - } - return v->scm; -} - -SCM_DEFINE(vcomponent_attr_list, "%vcomponent-attribute-list", 1, 0, 0, - (SCM component), - "Returns list of all keys in component.") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* comp = scm_foreign_object_ref (component, 0); - LLIST(strbuf)* keys = KEYS(TRIE(content_line))(&comp->clines); - - SCM llist = SCM_EOL; - FOR (LLIST, strbuf, s, keys) { - llist = scm_cons(scm_from_strbuf(s), llist); - } - - FFREE(LLIST(strbuf), keys); - - return llist; -} - -SCM_DEFINE(vcomponent_shallow_copy, "%vcomponent-shallow-copy", 1, 0, 0, - (SCM component), - "Creates a shallow copy of the given component.") -{ - scm_assert_foreign_object_type (vcomponent_type, component); - vcomponent* src = scm_foreign_object_ref (component, 0); - - vcomponent* dest = - (vcomponent*) scm_gc_malloc ( - sizeof(*dest), "vcomponent"); - INIT(vcomponent, dest, src->type, NULL); - vcomponent_copy (dest, src); - return scm_from_vcomponent (dest); -} - -void init_lib (void) { - init_vcomponent_type(); - content_set_lists = scm_make_weak_key_hash_table (scm_from_uint(0x100)); - -#ifndef SCM_MAGIC_SNARFER -#include "guile_interface.x" -#endif -} diff --git a/src/guile_interface.scm.c.disabled b/src/guile_interface.scm.c.disabled new file mode 100644 index 00000000..20c413df --- /dev/null +++ b/src/guile_interface.scm.c.disabled @@ -0,0 +1,261 @@ +#include "guile_interface.h" + +#include "calendar.h" +#include "guile_type_helpers.h" + +static SCM vcomponent_type; +static SCM content_set_lists; + +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, "%vcomponent-make", 0, 1, 0, + (SCM path), + "Loads a vdir iCalendar from the given path.") +{ + vcomponent* cal = + (vcomponent*) scm_gc_malloc ( + sizeof(*cal), "vcomponent"); + + if (SCM_UNBNDP(path)) { + INIT(vcomponent, cal); + } else { + INIT(vcomponent, cal, "ROOT"); + + char* p = scm_to_utf8_stringn(path, NULL); + read_vcalendar(cal, p); + free(p); + } + + return scm_from_vcomponent (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); + + const char* key = scm_i_string_chars (attr); + content_line* c = get_attributes (cal, key); + + if (c == NULL) { + vcomponent_push_val(cal, key, ""); + c = get_attributes (cal, key); + c->cval->key.scm = SCM_BOOL_F; + } + + SCM ptr = scm_from_pointer(c, NULL); + SCM ret = scm_hashq_ref (content_set_lists, ptr, SCM_BOOL_F); + if (! scm_is_false (ret)) { + return ret; + } + + SCM val, proplist; + SCM attrroot = scm_list_1(SCM_BOOL_F); + SCM attrlist = attrroot; + LLIST(strbuf) *triekeys, *trievals; + + /* For every instance of a line */ + FOR (LLIST, content_set, v, c) { + val = scm_from_strbuf(&v->key); + + if (! scm_is_pair(val)) { + // TODO look into using a weak hash table instead + + // TODO why is it an error to unprotect the object here? + // scm_from_strbuf should already have protected it... + // scm_gc_unprotect_object(v->key.scm); + SCM htable = scm_make_hash_table (scm_from_ulong(32)); + val = scm_cons(val, htable); + v->key.scm = val; + scm_gc_protect_object(v->key.scm); + + triekeys = KEYS(TRIE(param_set))(&v->val); + /* For every property key bound to the current attribute */ + FOR (LLIST, strbuf, k, triekeys) { + proplist = SCM_EOL; + + trievals = GET(TRIE(param_set))(&v->val, k->mem); + /* For every value bound to the current property */ + FOR (LLIST, strbuf, s, trievals) { + proplist = scm_cons(scm_from_strbuf(s), proplist); + } + + scm_hashq_set_x(htable, scm_from_strbuf_symbol(k), + scm_reverse(proplist)); + } + } + + attrlist = scm_cons(val, attrlist); + } + + /* create circular list */ + scm_set_cdr_x (attrroot, attrlist); + + + scm_hashq_set_x (content_set_lists, ptr, attrlist); + + return attrlist; +} + +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(LLIST(vcomponent))(&c->components)); +} + +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); + + SCM llist = SCM_EOL; + FOR (LLIST, vcomponent, v, &cal->components) { + llist = scm_cons(scm_from_vcomponent(v), llist); + } + return llist; +} + +SCM_DEFINE(vcomponent_filter_children_x, "%vcomponent-filter-children!", + 2, 0, 0, + (SCM pred, SCM component), + "Remove all children from component who DOESN'T satisfy `pred`") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* cal = scm_foreign_object_ref (component, 0); + + for (LINK(vcomponent)* l = FIRST(&cal->components); + l->after != NULL; + l = l->after) + { + if (scm_is_false(scm_call_1 (pred, scm_from_vcomponent(l->value)))) { + FFREE(vcomponent, l->value); + UNLINK(LINK(vcomponent))(l); + } + } + + return SCM_UNSPECIFIED; +} + +SCM_DEFINE(vcomponent_push_child_x, "%vcomponent-push-child!", 2, 0, 0, + (SCM component, SCM child), + "") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + scm_assert_foreign_object_type (vcomponent_type, child); + vcomponent* comp = scm_foreign_object_ref (component, 0); + vcomponent* chil = scm_foreign_object_ref (child, 0); + + PUSH(vcomponent)(comp, chil); + + return SCM_UNSPECIFIED; +} + +SCM_DEFINE (vcomponent_parent, "%vcomponent-parent", 1, 0, 0, + (SCM component), + "") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* comp = scm_foreign_object_ref (component, 0); + + vcomponent* parent = comp->parent; + if (strcmp(parent->type, "ROOT") == 0) { + return SCM_BOOL_F; + } else { + return scm_from_vcomponent(parent); + } +} + +SCM_DEFINE(vcomponent_typeof, "%vcomponent-get-type", 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); + + if (comp->scmtype == NULL) { + comp->scmtype = scm_from_utf8_symbol(comp->type); + } + + return comp->scmtype; +} + +SCM_DEFINE(vcomponent_set_type_x, "%vcomponent-set-type!", 2, 0, 0, + (SCM component, SCM type), + "Replace current type of vcomponent") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* comp = scm_foreign_object_ref (component, 0); + + if (comp->type) free (comp->type); + + char* ntype = scm_to_utf8_stringn (type, NULL); + comp->type = calloc(sizeof(*ntype), strlen(ntype) + 1); + strcpy(comp->type, ntype); + + return SCM_UNSPECIFIED; +} + +SCM scm_from_vcomponent(vcomponent* v) { + if (v->scm == NULL) { + v->scm = scm_make_foreign_object_1 (vcomponent_type, v); + scm_gc_protect_object(v->scm); + } + return v->scm; +} + +SCM_DEFINE(vcomponent_attr_list, "%vcomponent-attribute-list", 1, 0, 0, + (SCM component), + "Returns list of all keys in component.") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* comp = scm_foreign_object_ref (component, 0); + LLIST(strbuf)* keys = KEYS(TRIE(content_line))(&comp->clines); + + SCM llist = SCM_EOL; + FOR (LLIST, strbuf, s, keys) { + llist = scm_cons(scm_from_strbuf(s), llist); + } + + FFREE(LLIST(strbuf), keys); + + return llist; +} + +SCM_DEFINE(vcomponent_shallow_copy, "%vcomponent-shallow-copy", 1, 0, 0, + (SCM component), + "Creates a shallow copy of the given component.") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* src = scm_foreign_object_ref (component, 0); + + vcomponent* dest = + (vcomponent*) scm_gc_malloc ( + sizeof(*dest), "vcomponent"); + INIT(vcomponent, dest, src->type, NULL); + vcomponent_copy (dest, src); + return scm_from_vcomponent (dest); +} + +void init_lib (void) { + init_vcomponent_type(); + content_set_lists = scm_make_weak_key_hash_table (scm_from_uint(0x100)); + +#ifndef SCM_MAGIC_SNARFER +#include "guile_interface.x" +#endif +} 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 deleted file mode 100644 index 4d8da7d3..00000000 --- a/src/main.c +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include - -#include "calendar.h" -#include "macro.h" -#include "vcal.h" -#include "graphs.h" -#include "err.h" - -typedef struct { - int argc; - char** argv; -} arg; - -int arg_shift (arg* a) { - if (a->argc == 0) return 0; - - ++a->argv; - return --a->argc; - -} - -#define GETSET(C, KEY) \ - vcomponent_push_val((C), (KEY), "DUMMY VALUE"); \ - INFO_F("cline = %p", get_attributes((C), (KEY))); - -/* - * Tests defined here instead of in own header to ensure that all the - * correct modules are loaded. - */ -int run_tests() { - NEW(vcomponent, c); - INFO(All the following should print a valid pointer != 0x0); - GETSET(c, "FILENAME"); - GETSET(c, "X-HNH-FILENAME"); - GETSET(c, "DATA"); - GETSET(c, "DAT"); - GETSET(c, "DA"); - GETSET(c, "D"); - GETSET(c, "A"); - GETSET(c, "F"); - FFREE(vcomponent, c); - return 0; -} - -int main (int argc, char** argv) { - arg args = { .argc = argc, .argv = argv }; - - - if (arg_shift(&args) == 0) { - ERR("Please give something to parse, or some other flags"); - exit (1); - } - - if (strcmp(args.argv[0], "--run-tests") == 0) { - run_tests(); - return 0; - } - - char* rootpath = args.argv[0]; - SNEW(vcomponent, root, "ROOT", rootpath); - read_vcalendar(&root, rootpath); - - arg_shift(&args); - - if (args.argc == 0 || strcmp(args.argv[0], "-p") == 0) { - INFO_F("Parsed calendar file containing [%u] events", - root.components.length); - - puts("CAL : OBJ | Filename | Description"); - puts("----------+----------+------------"); - - /* This loops over all VCALENDAR's in root */ - FOR (LLIST, vcomponent, cal, &root.components) { - assert(strcmp(cal->type, "VCALENDAR") == 0); - - char* filename = vcomponent_get_val(cal, "X-HNH-FILENAME"); - - /* This loop over all VEVENT's in the current VCALENDAR */ - FOR (LLIST, vcomponent, ev, &cal->components) { - if (strcmp(ev->type, "VEVENT") != 0) continue; - - printf("%s | %s\n", - filename, - get_attributes(ev, "SUMMARY")->cval->key.mem); - } - } - } else if (strcmp(args.argv[0], "-g") == 0) { - /* TODO self might be broken */ - if (arg_shift(&args) == 0) { - FOR (LLIST, vcomponent, cal, &root.components) { - assert(strcmp(cal->type, "VCALENDAR") == 0); - - vcomponent* ev = FCHILD(cal); - - char target[0xFF]; - target[0] = '\0'; - strcat(target, "/tmp/dot/"); - strcat(target, vcomponent_get_val(ev, "X-HNH-FILENAME")); - strcat(target, ".dot"); - // create_graph(ev, target); - } - } else { - // create_graph(FCHILD(FCHILD(&root)), args.argv[0]); - INFO("Creating graph for single file"); - INFO_F("output = %s\n", args.argv[0]); - create_graph_vcomponent(&root, args.argv[0]); - } - } - - /* - char buf[0x20000]; - FMT(vcomponent)(&root, buf); - puts(buf); - */ - - FREE(vcomponent)(&root); -} diff --git a/src/main.c.old b/src/main.c.old new file mode 100644 index 00000000..4d8da7d3 --- /dev/null +++ b/src/main.c.old @@ -0,0 +1,120 @@ +#include +#include +#include +#include + +#include "calendar.h" +#include "macro.h" +#include "vcal.h" +#include "graphs.h" +#include "err.h" + +typedef struct { + int argc; + char** argv; +} arg; + +int arg_shift (arg* a) { + if (a->argc == 0) return 0; + + ++a->argv; + return --a->argc; + +} + +#define GETSET(C, KEY) \ + vcomponent_push_val((C), (KEY), "DUMMY VALUE"); \ + INFO_F("cline = %p", get_attributes((C), (KEY))); + +/* + * Tests defined here instead of in own header to ensure that all the + * correct modules are loaded. + */ +int run_tests() { + NEW(vcomponent, c); + INFO(All the following should print a valid pointer != 0x0); + GETSET(c, "FILENAME"); + GETSET(c, "X-HNH-FILENAME"); + GETSET(c, "DATA"); + GETSET(c, "DAT"); + GETSET(c, "DA"); + GETSET(c, "D"); + GETSET(c, "A"); + GETSET(c, "F"); + FFREE(vcomponent, c); + return 0; +} + +int main (int argc, char** argv) { + arg args = { .argc = argc, .argv = argv }; + + + if (arg_shift(&args) == 0) { + ERR("Please give something to parse, or some other flags"); + exit (1); + } + + if (strcmp(args.argv[0], "--run-tests") == 0) { + run_tests(); + return 0; + } + + char* rootpath = args.argv[0]; + SNEW(vcomponent, root, "ROOT", rootpath); + read_vcalendar(&root, rootpath); + + arg_shift(&args); + + if (args.argc == 0 || strcmp(args.argv[0], "-p") == 0) { + INFO_F("Parsed calendar file containing [%u] events", + root.components.length); + + puts("CAL : OBJ | Filename | Description"); + puts("----------+----------+------------"); + + /* This loops over all VCALENDAR's in root */ + FOR (LLIST, vcomponent, cal, &root.components) { + assert(strcmp(cal->type, "VCALENDAR") == 0); + + char* filename = vcomponent_get_val(cal, "X-HNH-FILENAME"); + + /* This loop over all VEVENT's in the current VCALENDAR */ + FOR (LLIST, vcomponent, ev, &cal->components) { + if (strcmp(ev->type, "VEVENT") != 0) continue; + + printf("%s | %s\n", + filename, + get_attributes(ev, "SUMMARY")->cval->key.mem); + } + } + } else if (strcmp(args.argv[0], "-g") == 0) { + /* TODO self might be broken */ + if (arg_shift(&args) == 0) { + FOR (LLIST, vcomponent, cal, &root.components) { + assert(strcmp(cal->type, "VCALENDAR") == 0); + + vcomponent* ev = FCHILD(cal); + + char target[0xFF]; + target[0] = '\0'; + strcat(target, "/tmp/dot/"); + strcat(target, vcomponent_get_val(ev, "X-HNH-FILENAME")); + strcat(target, ".dot"); + // create_graph(ev, target); + } + } else { + // create_graph(FCHILD(FCHILD(&root)), args.argv[0]); + INFO("Creating graph for single file"); + INFO_F("output = %s\n", args.argv[0]); + create_graph_vcomponent(&root, args.argv[0]); + } + } + + /* + char buf[0x20000]; + FMT(vcomponent)(&root, buf); + puts(buf); + */ + + FREE(vcomponent)(&root); +} 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 #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 #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.c deleted file mode 100644 index cd3ee412..00000000 --- a/src/struct.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "struct.h" - -#include - -SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 1, 0, 0, - (SCM type), - "") -{ - SCM str = scm_from_utf8_string("pr" "pw" "pw" "pr"); - SCM vcomponent_vtable = scm_make_vtable(str, SCM_BOOL_F); - return scm_c_make_struct (vcomponent_vtable, scm_from_int(0), - type, SCM_EOL, SCM_BOOL_F, - scm_make_hash_table(SCM_BOOL_F), - SCM_UNDEFINED); -} - - -SCM_DEFINE(scm_add_line_x, "add-line!", 3, 0, 0, - (SCM vcomponent, SCM key, SCM line), - "") -{ - scm_hash_set_x (scm_struct_ref(vcomponent, vcomponent_lines), key, line); - return SCM_UNSPECIFIED; -} - - -SCM_DEFINE(scm_add_child_x, "add-child!", 2, 0, 0, - (SCM vcomponent, SCM child), - "") -{ - scm_struct_set_x (child, vcomponent_parent, vcomponent); - scm_struct_set_x (vcomponent, vcomponent_children, - scm_cons (child, scm_struct_ref (vcomponent, vcomponent_children))); - - return SCM_UNSPECIFIED; -} - - -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); -} - - -SCM_DEFINE(scm_add_attribute_x, "add-attribute!", 3, 0, 0, - (SCM vline, SCM key, SCM value), - "") -{ - SCM table = scm_struct_ref (vline, vline_attributes); - scm_hash_set_x (table, key, - scm_cons(value, scm_hash_ref(table, key, SCM_EOL))); - return SCM_UNSPECIFIED; -} diff --git a/src/struct.scm.c b/src/struct.scm.c new file mode 100644 index 00000000..abbbba18 --- /dev/null +++ b/src/struct.scm.c @@ -0,0 +1,91 @@ +#include "struct.h" + +#include + +SCM vcomponent_vtable; +SCM vline_vtable; + +SCM_DEFINE(scm_make_vcomponent, "make-vcomponent", 0, 1, 0, + (SCM type), + "") +{ + + 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), + SCM_UNDEFINED); +} + + + +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), + "") +{ + scm_hash_set_x (scm_struct_ref(vcomponent, vcomponent_lines), key, line); + return SCM_UNSPECIFIED; +} + + +SCM_DEFINE(scm_add_child_x, "add-child!", 2, 0, 0, + (SCM vcomponent, SCM child), + "") +{ + scm_struct_set_x (child, vcomponent_parent, vcomponent); + scm_struct_set_x (vcomponent, vcomponent_children, + scm_cons (child, scm_struct_ref (vcomponent, vcomponent_children))); + + return SCM_UNSPECIFIED; +} + + +SCM_DEFINE(scm_make_vline, "make-vline", 0, 0, 0, + (), "") +{ + return scm_c_make_struct (vline_vtable, scm_from_int(0), + SCM_BOOL_F, scm_make_hash_table(SCM_BOOL_F), + SCM_UNDEFINED); +} + + +SCM_DEFINE(scm_add_attribute_x, "add-attribute!", 3, 0, 0, + (SCM vline, SCM key, SCM value), + "") +{ + SCM table = scm_struct_ref (vline, vline_attributes); + scm_hash_set_x (table, key, + 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 deleted file mode 100644 index 29177bf3..00000000 --- a/src/vcal.c +++ /dev/null @@ -1,175 +0,0 @@ -#include "vcal.h" - -#include - -#define TYPE strbuf -#include "linked_list.inc.h" -#undef TYPE - -#define TYPE param_set -#include "trie.inc.h" -#undef TYPE - -#define TYPE content_set -#include "linked_list.inc.h" -#undef TYPE - -#define T strbuf - #define V TRIE(param_set) - #include "pair.inc.h" - #undef V -#undef T - -#define TYPE content_line -// #include "hash.inc" -#include "trie.inc.h" -#undef TYPE - -#define TYPE vcomponent -// #include "vector.inc.h" -#include "linked_list.inc.h" -#undef TYPE - -INIT_F(vcomponent) { - INIT(TRIE(content_line), &self->clines); - INIT(LLIST(vcomponent), &self->components); - - // vcomponent_push_val (self, "X-HNH-FILENAME", "VIRTUAL"); - vcomponent_push_val (self, "X-HNH-SOURCETYPE", "virtual"); - char* type = "VIRTUAL"; - self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); - strcpy(self->type, type); - - self->parent = NULL; - self->scm = NULL; - self->scmtype = NULL; - - return 0; - -} - -INIT_F(vcomponent, const char* type) { - return INIT(vcomponent, self, type, NULL); -} - -INIT_F(vcomponent, const char* type, const char* filename) { - - INIT(TRIE(content_line), &self->clines); - INIT(LLIST(vcomponent), &self->components); - - if (filename != NULL) { - /* - * NOTE - * RFC-7986 adds additional parameters linked to this one. - * - `SOURCE' :: where a (possibly) updated version of the - * data can be found - * - `URL' :: Where the same data can be fonud, but - * differently (but not where the original data can be fonud - * again). - */ - vcomponent_push_val (self, "X-HNH-FILENAME", filename); - } - - self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); - strcpy(self->type, type); - - self->parent = NULL; - self->scm = NULL; - self->scmtype = NULL; - - return 0; -} - -content_line* get_attributes (vcomponent* ev, const char* key) { - size_t len = strlen(key) + 1; - char* cpy = (char*) (calloc(sizeof(*cpy), len)); - strncpy (cpy, key, len); - - content_line* ret = GET(TRIE(content_line))(&ev->clines, cpy); - - free (cpy); - return ret; -} - -FREE_F(vcomponent) { - free(self->type); - - if (FREE(TRIE(content_line))(&self->clines) != 0) { - ERR("Error freeing vcomponent"); - } - - FREE(LLIST(vcomponent))(&self->components); - - return 0; -} - -int PUSH(vcomponent)(vcomponent* parent, vcomponent* child) { - child->parent = parent; - return PUSH(LLIST(vcomponent))(&parent->components, child); -} - -int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) { - (void) a; - (void) b; - ERR("Deep copy not implemented for vcomponent"); - return -1; -} - -int vcomponent_copy(vcomponent* dest, vcomponent* src) { - - DEEP_COPY(TRIE(content_line))(&dest->clines, &src->clines); - - /* Children are the same objects */ - FOR(LLIST, vcomponent, c, &src->components) { - PUSH(LLIST(vcomponent))(&dest->components, c); - } - - dest->parent = src->parent; - // PUSH(vcomponent)(src->parent, dest); - - return 0; -} - -FMT_F(vcomponent) { - int seek = 0; - - for (int i = 0; i < 40; i++) fmtf("_"); - - seek += sprintf(buf + seek, _YELLOW); - seek += sprintf(buf + seek, "\nVComponet (Type := %s)\n", self->type); - seek += sprintf(buf + seek, _RESET); - seek += FMT(TRIE(content_line))(&self->clines, buf + seek); - seek += sprintf(buf + seek, "\nComponents:\n"); - FOR(LLIST, vcomponent, comp, &self->components) { - seek += FMT(vcomponent)(comp, buf + seek); - } - - return seek; -} - -int vcomponent_push_val (vcomponent* comp, const char* key, const char* val) { - NEW(content_line, cl); - NEW(content_set, cs); - strbuf_load(&cs->key, val); - PUSH(content_line)(cl, cs); - - char* key_cpy = calloc(sizeof(*key_cpy), strlen(key) + 1); - strcpy (key_cpy, key); - PUSH(TRIE(content_line))(&comp->clines, key_cpy, cl); - free (key_cpy); - - return 0; -} - -char* vcomponent_get_val (vcomponent* comp, const char* key) { - char* key_cpy = calloc(sizeof(*key_cpy), strlen(key) + 1); - strcpy (key_cpy, key); - content_line* cl = GET(TRIE(content_line))(&comp->clines, key_cpy); - free (key_cpy); - - if (cl != NULL && cl->cval != NULL) { - return cl->cval->key.mem; - } - - return NULL; -} diff --git a/src/vcal.c.old b/src/vcal.c.old new file mode 100644 index 00000000..29177bf3 --- /dev/null +++ b/src/vcal.c.old @@ -0,0 +1,175 @@ +#include "vcal.h" + +#include + +#define TYPE strbuf +#include "linked_list.inc.h" +#undef TYPE + +#define TYPE param_set +#include "trie.inc.h" +#undef TYPE + +#define TYPE content_set +#include "linked_list.inc.h" +#undef TYPE + +#define T strbuf + #define V TRIE(param_set) + #include "pair.inc.h" + #undef V +#undef T + +#define TYPE content_line +// #include "hash.inc" +#include "trie.inc.h" +#undef TYPE + +#define TYPE vcomponent +// #include "vector.inc.h" +#include "linked_list.inc.h" +#undef TYPE + +INIT_F(vcomponent) { + INIT(TRIE(content_line), &self->clines); + INIT(LLIST(vcomponent), &self->components); + + // vcomponent_push_val (self, "X-HNH-FILENAME", "VIRTUAL"); + vcomponent_push_val (self, "X-HNH-SOURCETYPE", "virtual"); + char* type = "VIRTUAL"; + self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); + strcpy(self->type, type); + + self->parent = NULL; + self->scm = NULL; + self->scmtype = NULL; + + return 0; + +} + +INIT_F(vcomponent, const char* type) { + return INIT(vcomponent, self, type, NULL); +} + +INIT_F(vcomponent, const char* type, const char* filename) { + + INIT(TRIE(content_line), &self->clines); + INIT(LLIST(vcomponent), &self->components); + + if (filename != NULL) { + /* + * NOTE + * RFC-7986 adds additional parameters linked to this one. + * - `SOURCE' :: where a (possibly) updated version of the + * data can be found + * - `URL' :: Where the same data can be fonud, but + * differently (but not where the original data can be fonud + * again). + */ + vcomponent_push_val (self, "X-HNH-FILENAME", filename); + } + + self->type = (char*) calloc(sizeof(*type), strlen(type) + 1); + strcpy(self->type, type); + + self->parent = NULL; + self->scm = NULL; + self->scmtype = NULL; + + return 0; +} + +content_line* get_attributes (vcomponent* ev, const char* key) { + size_t len = strlen(key) + 1; + char* cpy = (char*) (calloc(sizeof(*cpy), len)); + strncpy (cpy, key, len); + + content_line* ret = GET(TRIE(content_line))(&ev->clines, cpy); + + free (cpy); + return ret; +} + +FREE_F(vcomponent) { + free(self->type); + + if (FREE(TRIE(content_line))(&self->clines) != 0) { + ERR("Error freeing vcomponent"); + } + + FREE(LLIST(vcomponent))(&self->components); + + return 0; +} + +int PUSH(vcomponent)(vcomponent* parent, vcomponent* child) { + child->parent = parent; + return PUSH(LLIST(vcomponent))(&parent->components, child); +} + +int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) { + (void) a; + (void) b; + ERR("Deep copy not implemented for vcomponent"); + return -1; +} + +int vcomponent_copy(vcomponent* dest, vcomponent* src) { + + DEEP_COPY(TRIE(content_line))(&dest->clines, &src->clines); + + /* Children are the same objects */ + FOR(LLIST, vcomponent, c, &src->components) { + PUSH(LLIST(vcomponent))(&dest->components, c); + } + + dest->parent = src->parent; + // PUSH(vcomponent)(src->parent, dest); + + return 0; +} + +FMT_F(vcomponent) { + int seek = 0; + + for (int i = 0; i < 40; i++) fmtf("_"); + + seek += sprintf(buf + seek, _YELLOW); + seek += sprintf(buf + seek, "\nVComponet (Type := %s)\n", self->type); + seek += sprintf(buf + seek, _RESET); + seek += FMT(TRIE(content_line))(&self->clines, buf + seek); + seek += sprintf(buf + seek, "\nComponents:\n"); + FOR(LLIST, vcomponent, comp, &self->components) { + seek += FMT(vcomponent)(comp, buf + seek); + } + + return seek; +} + +int vcomponent_push_val (vcomponent* comp, const char* key, const char* val) { + NEW(content_line, cl); + NEW(content_set, cs); + strbuf_load(&cs->key, val); + PUSH(content_line)(cl, cs); + + char* key_cpy = calloc(sizeof(*key_cpy), strlen(key) + 1); + strcpy (key_cpy, key); + PUSH(TRIE(content_line))(&comp->clines, key_cpy, cl); + free (key_cpy); + + return 0; +} + +char* vcomponent_get_val (vcomponent* comp, const char* key) { + char* key_cpy = calloc(sizeof(*key_cpy), strlen(key) + 1); + strcpy (key_cpy, key); + content_line* cl = GET(TRIE(content_line))(&comp->clines, key_cpy); + free (key_cpy); + + if (cl != NULL && cl->cval != NULL) { + return cl->cval->key.mem; + } + + return NULL; +} diff --git a/src/vcal.h b/src/vcal.h deleted file mode 100644 index 2a3ad294..00000000 --- a/src/vcal.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef VCAL_H -#define VCAL_H - -#include - -#include - -#include "strbuf.h" - -#define TYPE strbuf -#include "linked_list.h" -// #include "trie.h" -#undef TYPE - -/* - * content_line: - * (a mapping) between a top level key, and everything it contains. - * content_set: - * A top level value, along with a list of kv pairs for all its - * possible parameters. - * param_set: - * A parameter key, along with a list of all its values. - */ - -#define param_set LLIST(strbuf) - -#define TYPE param_set -#include "trie.h" -#undef TYPE - -#define T strbuf - #define V TRIE(param_set) - #include "pair.h" - /* left := content | right := params */ - #define content_set PAIR(strbuf, TRIE(param_set)) - #undef V -#undef T - -#define TYPE content_set -#include "linked_list.h" -#undef TYPE - -#define content_line LLIST(content_set) - -/* - * Helper macros for accessing fields in - * content_line, content_set, and param_set - */ - -/* content_set */ -#define CLINE_CUR(c) ((c)->cval) - -/* strbuf */ -#define CLINE_CUR_VAL(c) (& CLINE_CUR(c)->key) - -/* TRIE(param_set) */ -#define CLINE_CUR_PARAMS(c) (& CLINE_CUR(c)->val) - -#define TYPE content_line -#include "trie.h" -#undef TYPE - -typedef struct s_vcomponent vcomponent; - -#define TYPE vcomponent -// #include "vector.h" -#include "linked_list.h" -#undef TYPE - -struct s_vcomponent { - /* VCALENDAR, VEVENT, ... */ - char* type; - vcomponent* parent; - TRIE(content_line) clines; - LLIST(vcomponent) components; - - /* - * Holds a Guile representation of this object. Used to always - * return the same foreign (for guile) object for the same - * vcomponent. - */ - SCM scm; - SCM scmtype; -}; - -#define FCHILD(v) FIRST_V(&(v)->components) - -INIT_F(vcomponent); -INIT_F(vcomponent, const char* type); -INIT_F(vcomponent, const char* type, const char* filename); -FREE_F(vcomponent); - -content_line* get_attributes (vcomponent* ev, const char* key); - -int add_content_line (vcomponent* ev, content_line* c); - -int vcomponent_push_val (vcomponent*, const char* key, const char* val); -char* vcomponent_get_val (vcomponent*, const char* key); - -/* - * Appends ev to cal. Doesn't copy ev. So make sure that it wont go - * out of scope. - */ -int PUSH(vcomponent)(vcomponent*, vcomponent*); - -/* - * Deep copy is currently not implemented for vcomponentes. - * The reason for this method being here is since some - * generic methods in other places complain otherwise. - */ -int DEEP_COPY(vcomponent)(vcomponent*, vcomponent*); - -/* - * "Shallow" copy of vcomponent. - */ -int vcomponent_copy(vcomponent*, vcomponent*); - -FMT_F(vcomponent); - -#endif /* VCAL_H */ diff --git a/src/vcal.h.old b/src/vcal.h.old new file mode 100644 index 00000000..2a3ad294 --- /dev/null +++ b/src/vcal.h.old @@ -0,0 +1,120 @@ +#ifndef VCAL_H +#define VCAL_H + +#include + +#include + +#include "strbuf.h" + +#define TYPE strbuf +#include "linked_list.h" +// #include "trie.h" +#undef TYPE + +/* + * content_line: + * (a mapping) between a top level key, and everything it contains. + * content_set: + * A top level value, along with a list of kv pairs for all its + * possible parameters. + * param_set: + * A parameter key, along with a list of all its values. + */ + +#define param_set LLIST(strbuf) + +#define TYPE param_set +#include "trie.h" +#undef TYPE + +#define T strbuf + #define V TRIE(param_set) + #include "pair.h" + /* left := content | right := params */ + #define content_set PAIR(strbuf, TRIE(param_set)) + #undef V +#undef T + +#define TYPE content_set +#include "linked_list.h" +#undef TYPE + +#define content_line LLIST(content_set) + +/* + * Helper macros for accessing fields in + * content_line, content_set, and param_set + */ + +/* content_set */ +#define CLINE_CUR(c) ((c)->cval) + +/* strbuf */ +#define CLINE_CUR_VAL(c) (& CLINE_CUR(c)->key) + +/* TRIE(param_set) */ +#define CLINE_CUR_PARAMS(c) (& CLINE_CUR(c)->val) + +#define TYPE content_line +#include "trie.h" +#undef TYPE + +typedef struct s_vcomponent vcomponent; + +#define TYPE vcomponent +// #include "vector.h" +#include "linked_list.h" +#undef TYPE + +struct s_vcomponent { + /* VCALENDAR, VEVENT, ... */ + char* type; + vcomponent* parent; + TRIE(content_line) clines; + LLIST(vcomponent) components; + + /* + * Holds a Guile representation of this object. Used to always + * return the same foreign (for guile) object for the same + * vcomponent. + */ + SCM scm; + SCM scmtype; +}; + +#define FCHILD(v) FIRST_V(&(v)->components) + +INIT_F(vcomponent); +INIT_F(vcomponent, const char* type); +INIT_F(vcomponent, const char* type, const char* filename); +FREE_F(vcomponent); + +content_line* get_attributes (vcomponent* ev, const char* key); + +int add_content_line (vcomponent* ev, content_line* c); + +int vcomponent_push_val (vcomponent*, const char* key, const char* val); +char* vcomponent_get_val (vcomponent*, const char* key); + +/* + * Appends ev to cal. Doesn't copy ev. So make sure that it wont go + * out of scope. + */ +int PUSH(vcomponent)(vcomponent*, vcomponent*); + +/* + * Deep copy is currently not implemented for vcomponentes. + * The reason for this method being here is since some + * generic methods in other places complain otherwise. + */ +int DEEP_COPY(vcomponent)(vcomponent*, vcomponent*); + +/* + * "Shallow" copy of vcomponent. + */ +int vcomponent_copy(vcomponent*, vcomponent*); + +FMT_F(vcomponent); + +#endif /* VCAL_H */ -- cgit v1.2.3