From 71e7b5fc4f28bcccd5fd9e27617b0ca2d13fc179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 6 Oct 2019 13:35:14 +0200 Subject: Remove old C code. --- Makefile | 12 -- src/calendar.c | 2 - src/calendar.h | 2 - src/graphs.c.old | 144 -------------------- src/graphs.h.old | 15 --- src/guile_interface.h.disabled | 28 ---- src/guile_interface.scm.c.disabled | 261 ------------------------------------- src/linked_list.h | 93 ------------- src/linked_list.inc.h | 179 ------------------------- src/main.c.old | 120 ----------------- src/pair.h | 19 --- src/pair.inc.h | 34 ----- src/trie.h | 54 -------- src/trie.inc.h | 231 -------------------------------- src/vcal.c.old | 175 ------------------------- src/vcal.h.old | 120 ----------------- 16 files changed, 1489 deletions(-) delete mode 100644 src/graphs.c.old delete mode 100644 src/graphs.h.old delete mode 100644 src/guile_interface.h.disabled delete mode 100644 src/guile_interface.scm.c.disabled delete mode 100644 src/linked_list.h delete mode 100644 src/linked_list.inc.h delete mode 100644 src/main.c.old delete mode 100644 src/pair.h delete mode 100644 src/pair.inc.h delete mode 100644 src/trie.h delete mode 100644 src/trie.inc.h delete mode 100644 src/vcal.c.old delete mode 100644 src/vcal.h.old diff --git a/Makefile b/Makefile index 6f25d5c5..a3fe93d2 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,6 @@ GUILE_C_FLAGS = -Lmodule \ all: $(SO_FILES) $(GO_FILES) -# Old C main -parse: $(O_FILES) - $(CC) -o $@ $^ $(LDFLAGS) - src/%.x : src/%.scm.c guile-snarf -o $@ $< $(CFLAGS) @@ -56,13 +52,6 @@ obj/%.scm.go: %.scm # $(SO_FILES) @mkdir -p obj guild compile $(GUILE_C_FLAGS) -o $@ $< -.SECONDARY += %.dot -%.dot: testcal/%.ics parse - ./parse $< -g $@ - -%.pdf: %.dot - dot -Tpdf -o $@ $< - html: $(GO_FILES) mkdir -p html ln -sf ../static html @@ -73,7 +62,6 @@ tags: $(C_FILES) $(H_FILES) ./rfc-tags rfc5545.txt >> tags clean: - -rm parse -rm -r html -rm -r obj -rm -r lib diff --git a/src/calendar.c b/src/calendar.c index f3a9b254..1362ee2e 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -11,7 +11,6 @@ #include #include "struct.h" - #include "parse.h" #include "err.h" @@ -46,7 +45,6 @@ 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_from_utf8_string("file")); scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); char* resolved_path = realpath(path, NULL); diff --git a/src/calendar.h b/src/calendar.h index 3e6941f9..776d9900 100644 --- a/src/calendar.h +++ b/src/calendar.h @@ -3,8 +3,6 @@ #include -// #include "vcal.h" - /* * Reads all ics flies in path into the given vcomponent. The * component is assumed to be a abstract ROOT element, whose first diff --git a/src/graphs.c.old b/src/graphs.c.old deleted file mode 100644 index 51a26117..00000000 --- a/src/graphs.c.old +++ /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.h.old b/src/graphs.h.old deleted file mode 100644 index fe521003..00000000 --- a/src/graphs.h.old +++ /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/guile_interface.h.disabled b/src/guile_interface.h.disabled deleted file mode 100644 index 76ec24d3..00000000 --- a/src/guile_interface.h.disabled +++ /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.scm.c.disabled b/src/guile_interface.scm.c.disabled deleted file mode 100644 index 20c413df..00000000 --- a/src/guile_interface.scm.c.disabled +++ /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/linked_list.h b/src/linked_list.h deleted file mode 100644 index 0d32b988..00000000 --- a/src/linked_list.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef LINKED_LIST_H -#define LINKED_LIST_H - -#include "macro.h" - -#define LLIST(T) TEMPL(llist, T) -#define LINK(T) TEMPL(llist_link, T) - -#define UNLINK(T) TEMPL(unlink, T) - -#endif /* LINKED_LIST_H */ -#ifdef TYPE - -typedef struct LINK(TYPE) { - struct LINK(TYPE)* before; - struct LINK(TYPE)* after; - TYPE* value; -} LINK(TYPE); - -#define L(link) (link)->value - -typedef struct { - LINK(TYPE)* head; - LINK(TYPE)* tail; - LINK(TYPE)* cur; - TYPE* cval; - int length; -} LLIST(TYPE); - -#define FIRST(lst) (lst)->head->after -#define FIRST_V(lst) (lst)->head->after->value -#define LAST(lst) (lst)->tail->before -#define LAST_V(lst) (lst)->tail->before->value - -INIT_F ( LLIST(TYPE) ); - -/* - * NOTE freeing a linked list alsa FFREE's all its contents. - * TODO some form of shared pointer to ensure nothing is free'd twice - * would be a good idea. - */ -FREE_F ( LLIST(TYPE) ); - -INIT_F ( LINK(TYPE) ); -INIT_F ( LINK(TYPE), TYPE* val ); -FREE_F ( LINK(TYPE) ); - -int UNLINK(LINK(TYPE)) ( LINK(TYPE)* ); - -int PUSH(LLIST(TYPE)) ( LLIST(TYPE)*, TYPE* ); -TYPE* PEEK(LLIST(TYPE)) ( LLIST(TYPE)* ); -TYPE* POP(LLIST(TYPE)) ( LLIST(TYPE)* ); - -int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ); - -int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new_ ); - -int SIZE(LLIST(TYPE)) ( LLIST(TYPE)* llist ); -int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist ); - -/* - * Resets a linked list by removing all it's objects. - * FREE's all elements stored in the list. - */ -int RESET(LLIST(TYPE)) ( LLIST(TYPE)* llist ); - -/* - * Takes to lists, and merges them into a single one. Destroys new_ in - * the process. - */ -LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new_); - -FMT_F(LLIST(TYPE)); - -/* Iterator */ - -#define __PRE_LLIST(T, l, set) \ - T* l; LINK(T)* __INTER(l); - -#define PRE_FOR_LLIST(T) __PRE_LLIST - -// #define __BEG_LLIST(v, set) v = (set)->head -#define __BEG_LLIST(T, l, set) __INTER(l) = FIRST(set), l = L(__INTER(l)) -#define BEG_LLIST(T) __BEG_LLIST - -#define __END_LLIST(T, l, set) __INTER(l) != (set)->tail -#define END_LLIST(T) __END_LLIST - -#define __NXT_LLIST(T, l, set) __INTER(l) = __INTER(l)->after, l = L(__INTER(l)) -// #define __NXT_LLIST(T, l, set) l = L(__INTER(l) = __INTER(l)->after) -#define NXT_LLIST(T) __NXT_LLIST - -#endif /* TYPE */ diff --git a/src/linked_list.inc.h b/src/linked_list.inc.h deleted file mode 100644 index 3984e485..00000000 --- a/src/linked_list.inc.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef TYPE -#error "Set TYPE before including self file" -#else - -INIT_F ( LLIST(TYPE) ) { - self->length = 0; - NEW(LINK(TYPE), head); - NEW(LINK(TYPE), tail); - self->head = head; - self->tail = tail; - head->after = tail; - tail->before = head; - self->cur = head; - self->cval = head->value; - return 0; -} - -FREE_F (LINK(TYPE)) { - UNLINK(LINK(TYPE))(self); - - if (self->value != NULL) FFREE(TYPE, self->value); - return 0; -} - -FREE_F( LLIST(TYPE) ) { - LINK(TYPE) *n, *next; - n = self->head; - while ( n != NULL ) { - next = n->after; - FFREE(LINK(TYPE), n); - n = next; - } - - self->length = -1; - - return 0; -} - -INIT_F ( LINK(TYPE) ) { - self->before = NULL; - self->after = NULL; - self->value = NULL; - return 0; -} - -INIT_F ( LINK(TYPE), TYPE* val ) { - self->before = NULL; - self->after = NULL; - self->value = val; - return 0; -} - -int UNLINK(LINK(TYPE)) ( LINK(TYPE)* self ) { - if (self->before != NULL) self->before->after = self->after; - if (self->after != NULL) self->after->before = self->before; - return 0; -} - - -int PUSH(LLIST(TYPE)) ( LLIST(TYPE)* lst, TYPE* val) { - NEW(LINK(TYPE), link, val); - - link->after = FIRST(lst); - FIRST(lst) = link; - - link->after->before = link; - link->before = lst->head; - - ++lst->length; - - // TODO do I want to change that? - lst->cur = link; - lst->cval = link->value; - - return 0; -} - -TYPE* PEEK(LLIST(TYPE)) ( LLIST(TYPE)* lst ) { - if (EMPTY(LLIST(TYPE))(lst)) return NULL; - - return FIRST(lst)->value; -} - -TYPE* POP(LLIST(TYPE)) ( LLIST(TYPE)* lst) { - if (EMPTY(LLIST(TYPE))(lst)) return NULL; - - LINK(TYPE)* frst = FIRST(lst); - UNLINK(LINK(TYPE))(frst); - - TYPE* retval = frst->value; - --lst->length; - free (frst); - return retval; -} - -int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ) { - LINK(TYPE)* n = FIRST(src); - - while (n->after != NULL) { - NEW(TYPE, cpy); - DEEP_COPY(TYPE)(cpy, n->value); - PUSH(LLIST(TYPE)) ( dest, cpy ); - n = n->after; - } - - return 0; -} - -/* - * Adds two linked lists together. - * O(1) time. - * destroys new__ in the process, but keeps the elements. - * make sure to free(new__) after. - */ -int APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new__ ) { - - /* Link end of dest onto start of new__. */ - LAST(dest)->after = FIRST(new__); - FIRST(new__)->before = LAST(dest); - - /* Free the two now not needed end links. */ - free(new__->head); - free(dest->tail); - - /* Update dest with new__ tail ptr. */ - dest->tail = new__->tail; - - dest->length += new__->length; - - return 0; -} - -int SIZE(LLIST(TYPE)) ( LLIST(TYPE)* llist ) { - return llist->length; -} - -int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist ) { - return FIRST(llist) == llist->tail; -} - -LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new__) { - if (dest == NULL) return new__; - APPEND(LLIST(TYPE))(dest, new__); - free(new__); - return dest; -} - -int RESET(LLIST(TYPE)) ( LLIST(TYPE)* llist ) { - - LINK(TYPE) *link = FIRST(llist), *next; - /* - * Manual looping rather than itterators since we destroyed the - * loop variable. - */ - while (link != llist->tail) { - next = link->after; - FFREE(LINK(TYPE), link); - link = next; - } - - llist->cur = llist->head; - llist->cval = llist->head->value; - - return 0; -} - -FMT_F(LLIST(TYPE)) { - int seek = 0; - fmtf("("); - FOR(LLIST, TYPE, v, self) { - seek += FMT(TYPE)(v, buf + seek); - fmtf(" "); - } - fmtf(")"); - - return seek; -} - -#endif /* TYPE */ diff --git a/src/main.c.old b/src/main.c.old deleted file mode 100644 index 4d8da7d3..00000000 --- a/src/main.c.old +++ /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/pair.h b/src/pair.h deleted file mode 100644 index e96cf180..00000000 --- a/src/pair.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PAIR_H -#define PAIR_H - -#define PAIR(T, V) TEMPL2(pair, T, V) - -#endif /* PAIR_H */ -#if defined(T) && defined(V) - -typedef struct { - T key; - V val; -} PAIR(T, V); - -INIT_F(PAIR(T, V)); -FREE_F(PAIR(T, V)); -FMT_F(PAIR(T, V)); -int DEEP_COPY(PAIR(T, V)) (PAIR(T, V)* dest, PAIR(T, V)* src); - -#endif diff --git a/src/pair.inc.h b/src/pair.inc.h deleted file mode 100644 index c42b2dfd..00000000 --- a/src/pair.inc.h +++ /dev/null @@ -1,34 +0,0 @@ -#if ! (defined(T) && defined(V)) -#error "Both T and V must be defiend here" -#else - -INIT_F(PAIR(T, V)) { - INIT(T, &self->key); - INIT(V, &self->val); - - return 0; -} - -FREE_F(PAIR(T, V)) { - FREE(T)(&self->key); - FREE(V)(&self->val); - - return 0; -} - -FMT_F(PAIR(T, V)) { - char lbuf[0x100]; - char rbuf[0x1000]; - FMT(T)(&self->key, lbuf); - FMT(V)(&self->val, rbuf); - - return sprintf(buf, "<%s, %s>", lbuf, rbuf); -} - -int DEEP_COPY(PAIR(T, V)) (PAIR(T, V)* dest, PAIR(T, V)* src) { - DEEP_COPY(T)(&dest->key, &src->key); - DEEP_COPY(V)(&dest->val, &src->val); - return 0; -} - -#endif /* T & V */ diff --git a/src/trie.h b/src/trie.h deleted file mode 100644 index 9de38be3..00000000 --- a/src/trie.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef TRIE_H -#define TRIE_H - -#include - -#include "macro.h" - -#define TRIE(T) TEMPL(trie, T) -#define TRIE_NODE(T) TEMPL(trie_node, T) - -#endif /* TRIE_H */ -#ifdef TYPE - -#include "linked_list.h" -#include "strbuf.h" - -typedef struct TRIE_NODE(TYPE) { - char c; - TYPE* value; - struct TRIE_NODE(TYPE)* next; - struct TRIE_NODE(TYPE)* child; -} TRIE_NODE(TYPE); - -typedef struct { - TRIE_NODE(TYPE)* root; -} TRIE(TYPE); - - -INIT_F ( TRIE(TYPE) ); - -INIT_F (TRIE_NODE(TYPE), char c); - -INIT_F (TRIE_NODE(TYPE), - char c, TRIE_NODE(TYPE)* next, TRIE_NODE(TYPE)* child ); - -int PUSH(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key, TYPE* val ); - -TYPE* GET(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key ); - -FREE_F(TRIE_NODE(TYPE)); - -FREE_F(TRIE(TYPE)); - -int EMPTY(TRIE(TYPE))(TRIE(TYPE)*); - -FMT_F(TRIE_NODE(TYPE)); -FMT_F(TRIE(TYPE)); - -int DEEP_COPY(TRIE_NODE(TYPE)) (TRIE_NODE(TYPE)* dest, TRIE_NODE(TYPE)* src); -int DEEP_COPY(TRIE(TYPE)) (TRIE(TYPE)* dest, TRIE(TYPE)* src); - -LLIST(strbuf)* KEYS(TRIE(TYPE)) (TRIE(TYPE)*); - -#endif /* TYPE */ diff --git a/src/trie.inc.h b/src/trie.inc.h deleted file mode 100644 index 64e5239d..00000000 --- a/src/trie.inc.h +++ /dev/null @@ -1,231 +0,0 @@ -#ifndef TYPE -#error "Set TYPE before including self file" -#else - -#include - -#include "err.h" -#include "macro.h" -#include "linked_list.inc.h" -#include "strbuf.h" - -INIT_F ( TRIE(TYPE) ) { - NEW(TRIE_NODE(TYPE), t, '\0'); - self->root = t; - return 0; -} - -INIT_F (TRIE_NODE(TYPE), char c) { - self->c = c; - self->value = NULL; - self->next = NULL; - self->child = NULL; - return 0; -} - -INIT_F (TRIE_NODE(TYPE), - char c, - TRIE_NODE(TYPE)* next, - TRIE_NODE(TYPE)* child ) -{ - self->c = c; - self->next = next; - self->child = child; - return 0; -} - -int PUSH(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key, TYPE* val ) { - TRIE_NODE(TYPE) *cur, *last; - - last = trie->root; - cur = last->child; - - char* subkey = key; - - while (1) { - if (cur == NULL) { - /* Build direct LL for remaining subkey */ - for (char* c = subkey; c[0] != '\0'; c++) { - NEW(TRIE_NODE(TYPE), t, *c); - last->child = t; - last = t; - } - last->value = RESOLVE(TYPE)(last->value, val); - return 0; - } else if (cur->c == subkey[0]) { - /* This node belongs to the key, - * Decend further */ - last = cur; - cur = cur->child; - subkey++; - } else if (subkey[0] == '\0') { - /* Key finished */ - last->value = RESOLVE(TYPE)(last->value, val); - return 0; - } else if (cur->next != NULL) { - /* This node was not part of the set, but it's sibling might */ - cur = cur->next; - /* `last` not set since we aren't moving down */ - } else { - /* No node on self level was part of the set, create a new__ - * sibling and follow down that parse */ - NEW(TRIE_NODE(TYPE), t, *subkey); - cur->next = t; - last = cur; - cur = t; - } - } - - return 0; -} - -/* - * TODO what happens when I give an invalid key? - */ -TYPE* GET(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key ) { - TRIE_NODE(TYPE)* n = trie->root->child; - char* subkey = key; - - while (n != NULL) { - if (subkey[0] == n->c) { - if (subkey[1] == '\0') { - /* Wanted node found, - * value can however be NULL */ - return n->value; - } else { - n = n->child; - subkey++; - } - } else { - n = n->next; - } - - } - - /* Position not found */ - return 0; -} - -FREE_F(TRIE_NODE(TYPE)) { - if (self == NULL) return 0; - if (self->value != NULL) FFREE(TYPE, self->value); - if (self->next != NULL) FREE(TRIE_NODE(TYPE))(self->next); - if (self->child != NULL) FREE(TRIE_NODE(TYPE))(self->child); - free (self); - return 0; -} - -FREE_F(TRIE(TYPE)) { - if (self->root->c != '\0') { - // ERR("Invalid trie"); - return 1; - } - return FREE(TRIE_NODE(TYPE))(self->root); -} - -int EMPTY(TRIE(TYPE))(TRIE(TYPE)* self) { - return self->root->child == NULL; -} - -FMT_F(TRIE_NODE(TYPE)) { - - va_list ap; - va_start(ap, buf); - int argc = va_arg(ap, int); - int depth = argc >= 1 - ? va_arg(ap, int) - : 0; - va_end(ap); - - int seek = 0; - - TRIE_NODE(TYPE)* n = self; - - if (n == NULL) { fmtf("\n"); } - while (n != NULL) { - fmtf("|"); - // FOR(int, i, depth) fmtf(" "); - for (int i = 0; i < depth; i++) fmtf(" "); - fmtf("%c ", n->c == '\0' ? '0' : n->c); - if (n->value != NULL) { - seek += FMT(TYPE)(n->value, buf + seek); - fmtf("\n"); - } - - if (n->child != NULL) { - fmtf("\n"); - seek += FMT(TRIE_NODE(TYPE))(n->child, buf + seek, depth + 1); - } - n = n->next; - } - return seek; - -} - -FMT_F(TRIE(TYPE)) { - int seek = 0; - fmtf("Trie: %p: {", self); - if (EMPTY(TRIE(TYPE))(self)) { - fmtf(" [EMPTY] "); - } else { - fmtf("\n"); - seek += FMT(TRIE_NODE(TYPE))(self->root->child, buf + seek); - } - fmtf("}"); - return seek; -} - -int DEEP_COPY(TRIE_NODE(TYPE)) (TRIE_NODE(TYPE)* dest, TRIE_NODE(TYPE)* src) { - dest->c = src->c; - - if (src->value != NULL) { - RENEW(TYPE, dest->value); - DEEP_COPY(TYPE)(dest->value, src->value); - } - - if (src->next != NULL) { - RENEW(TRIE_NODE(TYPE), dest->next, '\0'); - DEEP_COPY(TRIE_NODE(TYPE))(dest->next, src->next); - } - - if (src->child != NULL) { - RENEW(TRIE_NODE(TYPE), dest->child, '\0'); - DEEP_COPY(TRIE_NODE(TYPE))(dest->child, src->child); - } - - return 0; -} - -int DEEP_COPY(TRIE(TYPE)) (TRIE(TYPE)* dest, TRIE(TYPE)* src) { - return DEEP_COPY(TRIE_NODE(TYPE))(dest->root, src->root); -} - -void KEYS(TRIE_NODE(TYPE)) (TRIE_NODE(TYPE)* node, LLIST(strbuf)* list, strbuf* path) { - if (node == NULL) return; - - - if (node->value != NULL) { - strbuf_append(path, node->c); - NEW(strbuf, c); - DEEP_COPY(strbuf)(c, path); - PUSH(LLIST(strbuf))(list, c); - strbuf_pop(path); - } - if (node->next != NULL) { - KEYS(TRIE_NODE(TYPE)) (node->next, list, path); - } - if (node->child != NULL) { - if (node->c != '\0') strbuf_append(path, node->c); - KEYS(TRIE_NODE(TYPE)) (node->child, list, path); - if (node->c != '\0') strbuf_pop(path); - } -} - -LLIST(strbuf)* KEYS(TRIE(TYPE)) (TRIE(TYPE)* trie) { - NEW(LLIST(strbuf), retlist); - SNEW(strbuf, key); - KEYS(TRIE_NODE(TYPE)) (trie->root, retlist, &key); - return retlist; -} - -#endif /* TYPE */ diff --git a/src/vcal.c.old b/src/vcal.c.old deleted file mode 100644 index 29177bf3..00000000 --- a/src/vcal.c.old +++ /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.h.old b/src/vcal.h.old deleted file mode 100644 index 2a3ad294..00000000 --- a/src/vcal.h.old +++ /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 */ -- cgit v1.2.3