diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-03-08 10:05:35 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-03-08 10:05:35 +0100 |
commit | 0dff6c5d179aeb9e1ba3fc5f4dd679987e342036 (patch) | |
tree | c43ef6a0ef0fe6f684928a226a0f439975b20e01 | |
parent | Work on recuring event stream. (diff) | |
download | calp-0dff6c5d179aeb9e1ba3fc5f4dd679987e342036.tar.gz calp-0dff6c5d179aeb9e1ba3fc5f4dd679987e342036.tar.xz |
Remove C vector library.
Diffstat (limited to '')
-rw-r--r-- | graphs.c | 5 | ||||
-rw-r--r-- | guile_interface.scm.c | 9 | ||||
-rw-r--r-- | guile_type_helpers.c | 10 | ||||
-rw-r--r-- | guile_type_helpers.h | 2 | ||||
-rw-r--r-- | main.c | 13 | ||||
-rw-r--r-- | parse.c | 6 | ||||
-rw-r--r-- | parse.h | 6 | ||||
-rw-r--r-- | vcal.c | 27 | ||||
-rw-r--r-- | vcal.h | 9 | ||||
-rw-r--r-- | vector.h | 40 | ||||
-rw-r--r-- | vector.inc.h | 51 |
11 files changed, 44 insertions, 134 deletions
@@ -49,10 +49,7 @@ int helper_vcomponent (vcomponent* root, FILE* f) { fputs("}", f); } - vcomponent* child; - for (size_t i = 0; i < root->components.length; i++) { - child = GET(VECT(vcomponent))(&root->components, i); - if (child == NULL) continue; + FOR(LLIST, vcomponent, child, &root->components) { fprintf(f, "\"%p\" -> \"%p\"\n", root, child); helper_vcomponent(child, f); } diff --git a/guile_interface.scm.c b/guile_interface.scm.c index 761bf7c2..2dcff513 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -96,7 +96,7 @@ SCM_DEFINE (vcomponent_child_count, "%vcomponent-child-count", 1, 0, 0, { scm_assert_foreign_object_type (vcomponent_type, component); vcomponent* c = scm_foreign_object_ref (component, 0); - return scm_from_size_t (SIZE(VECT(vcomponent))(&c->components)); + return scm_from_size_t (SIZE(LLIST(vcomponent))(&c->components)); } SCM_DEFINE(vcomponent_children, "%vcomponent-children", 1, 0, 0, @@ -105,7 +105,12 @@ SCM_DEFINE(vcomponent_children, "%vcomponent-children", 1, 0, 0, { scm_assert_foreign_object_type (vcomponent_type, component); vcomponent* cal = scm_foreign_object_ref (component, 0); - return scm_from_vector(&cal->components); + + SCM llist = SCM_EOL; + FOR (LLIST, vcomponent, v, &cal->components) { + llist = scm_cons(scm_from_vcomponent(v), llist); + } + return llist; } SCM_DEFINE(vcomponent_push_child_x, "%vcomponent-push-child!", 2, 0, 0, diff --git a/guile_type_helpers.c b/guile_type_helpers.c index ae433b01..e231f2b1 100644 --- a/guile_type_helpers.c +++ b/guile_type_helpers.c @@ -11,13 +11,3 @@ SCM scm_from_strbuf(strbuf* s) { return s->scm; } - -SCM scm_from_vector(VECT(vcomponent)* vect) { - SCM l = SCM_EOL; - for (size_t i = 0; i < vect->length; i++) { - vcomponent* v = GET(VECT(vcomponent))(vect, i); - l = scm_cons(scm_from_vcomponent(v), l); - } - return scm_reverse(l); -} - diff --git a/guile_type_helpers.h b/guile_type_helpers.h index 005ee34b..2ff177e1 100644 --- a/guile_type_helpers.h +++ b/guile_type_helpers.h @@ -10,6 +10,4 @@ SCM scm_from_strbuf(strbuf* s); -SCM scm_from_vector(VECT(vcomponent)* vect); - #endif /* GUILE_TYPE_HELPERS_H */ @@ -44,20 +44,16 @@ int main (int argc, char** argv) { puts("----------+----------+------------"); /* This loops over all VCALENDAR's in root */ - for (size_t i = 0; i < root.components.length; i++) { - vcomponent* cal = GET(VECT(vcomponent))(&root.components, i); + 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 (size_t j = 0; j < cal->components.length; j++) { - vcomponent* ev = GET(VECT(vcomponent))(&cal->components, j); - + FOR (LLIST, vcomponent, ev, &cal->components) { if (strcmp(ev->type, "VEVENT") != 0) continue; - printf("%3lu : %3lu | %s | %s\n", - i + 1, j + 1, + printf("%s | %s\n", filename, get_property(ev, "SUMMARY")->cur->value->key.mem); } @@ -65,8 +61,7 @@ int main (int argc, char** argv) { } else if (strcmp(args.argv[0], "-g") == 0) { /* TODO self might be broken */ if (arg_shift(&args) == 0) { - for (size_t i = 0; i < root.components.length; i++) { - vcomponent* cal = GET(VECT(vcomponent))(&root.components, i); + FOR (LLIST, vcomponent, cal, &root.components) { assert(strcmp(cal->type, "VCALENDAR") == 0); vcomponent* ev = FCHILD(cal); @@ -9,9 +9,9 @@ #include "err.h" -#define TYPE vcomponent -#include "linked_list.inc.h" -#undef TYPE +// #define TYPE vcomponent +// #include "linked_list.inc.h" +// #undef TYPE #define T strbuf #define V strbuf @@ -7,9 +7,9 @@ #include "strbuf.h" #include "vcal.h" -#define TYPE vcomponent -#include "linked_list.h" -#undef TYPE +// #define TYPE vcomponent +// #include "linked_list.h" +// #undef TYPE /* * The standard says that no line should be longer than 75 octets. @@ -26,7 +26,8 @@ #undef TYPE #define TYPE vcomponent -#include "vector.inc.h" +// #include "vector.inc.h" +#include "linked_list.inc.h" #undef TYPE INIT_F(vcomponent) { @@ -42,7 +43,7 @@ INIT_F(vcomponent, const char* type) { INIT_F(vcomponent, const char* type, const char* filename) { INIT(TRIE(content_line), &self->clines); - INIT(VECT(vcomponent), &self->components); + INIT(LLIST(vcomponent), &self->components); if (filename != NULL) { vcomponent_push_val (self, "X-HNH-FILENAME", filename); @@ -75,14 +76,14 @@ FREE_F(vcomponent) { ERR("Error freeing vcomponent"); } - FREE(VECT(vcomponent))(&self->components); + FREE(LLIST(vcomponent))(&self->components); return 0; } int PUSH(vcomponent)(vcomponent* parent, vcomponent* child) { child->parent = parent; - return PUSH(VECT(vcomponent))(&parent->components, child); + return PUSH(LLIST(vcomponent))(&parent->components, child); } int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) { @@ -92,17 +93,31 @@ int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) { 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); + } + + 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, "\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(VECT, vcomponent, comp, &self->components) { + FOR(LLIST, vcomponent, comp, &self->components) { seek += FMT(vcomponent)(comp, buf + seek); } @@ -19,7 +19,7 @@ * 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. + * A parameter key, along with a list of all its values. */ #define param_set LLIST(strbuf) @@ -63,19 +63,20 @@ typedef struct s_vcomponent vcomponent; #define TYPE vcomponent -#include "vector.h" +// #include "vector.h" +#include "linked_list.h" #undef TYPE struct s_vcomponent { char* type; vcomponent* parent; TRIE(content_line) clines; - VECT(vcomponent) components; + LLIST(vcomponent) components; SCM scm; }; -#define FCHILD(v) GET(VECT(vcomponent))(&(v)->components, 0) +#define FCHILD(v) FIRST_V(&(v)->components) INIT_F(vcomponent); INIT_F(vcomponent, const char* type); diff --git a/vector.h b/vector.h deleted file mode 100644 index 073252bf..00000000 --- a/vector.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef VECTOR_H -#define VECTOR_H - -#include <stdlib.h> -#include "macro.h" - -#define VECT(T) TEMPL(vect, T) - -#endif /* VECTOR_H */ - -#ifdef TYPE - -typedef struct { - unsigned int length; - unsigned int alloc; - TYPE** items; -} VECT(TYPE); - -INIT_F(VECT(TYPE)); -FREE_F(VECT(TYPE)); - -int PUSH(VECT(TYPE))(VECT(TYPE)*, TYPE*); -TYPE* GET(VECT(TYPE))(VECT(TYPE)*, unsigned int idx); -int EMPTY(VECT(TYPE))(VECT(TYPE)*); -unsigned int SIZE(VECT(TYPE))(VECT(TYPE)*); - -#define __PRE_VECT(T, i, set) \ - unsigned int __INTER(i) = 0; T* i; -#define PRE_FOR_VECT(T) __PRE_VECT - -#define __BEG_VECT(T, i, set) i = GET(VECT(T))(set, __INTER(i)) -#define BEG_VECT(T) __BEG_VECT - -#define __END_VECT(T, i, set) __INTER(i) < SIZE(VECT(T))(set) -#define END_VECT(T) __END_VECT - -#define __NXT_VECT(T, i, set) i = GET(VECT(T))(set, ++__INTER(i)) -#define NXT_VECT(T) __NXT_VECT - -#endif /* TYPE */ diff --git a/vector.inc.h b/vector.inc.h deleted file mode 100644 index 2b23eadc..00000000 --- a/vector.inc.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TYPE -#error "Set TYPE before including self file" -#else - -#include "macro.h" -#include "err.h" - -INIT_F(VECT(TYPE)) { - self->length = 0; - self->alloc = 1; - self->items = (TYPE**) calloc(sizeof(*self->items), self->alloc); - return 0; -} - -FREE_F(VECT(TYPE)) { - for (unsigned int i = 0; i < self->length; i++) { - FFREE(TYPE, self->items[i]); - } - free(self->items); - return 0; -} - -int PUSH(VECT(TYPE))(VECT(TYPE)* self, TYPE* t) { - if (self->length + 1 > self->alloc) { - self->alloc <<= 1; - self->items = (TYPE**) realloc(self->items, sizeof(*self->items) * self->alloc); - } - - self->items[self->length] = t; - ++self->length; - return 0; -} - -TYPE* GET(VECT(TYPE))(VECT(TYPE)* self, unsigned int idx) { - if (idx >= self->length) { - ERR("Index out of range"); - return NULL; - } - - return self->items[idx]; -} - -int EMPTY(VECT(TYPE))(VECT(TYPE)* self) { - return self->length == 0; -} - -unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* self) { - return self->length; -} - -#endif /* TYPE */ |