aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-10-06 13:41:00 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-10-06 13:41:00 +0200
commitab964d17145114eda93cda35f69a4b1e1779e242 (patch)
tree2288777a11a1d44539f3790a3aa1e60051452667
parentMinor cleanup in scheme code. (diff)
downloadcalp-ab964d17145114eda93cda35f69a4b1e1779e242.tar.gz
calp-ab964d17145114eda93cda35f69a4b1e1779e242.tar.xz
Cleanup in C code.
-rw-r--r--src/guile_type_helpers.c10
-rw-r--r--src/guile_type_helpers.h4
-rw-r--r--src/parse.c53
-rw-r--r--src/parse.h12
-rw-r--r--src/struct.scm.c2
5 files changed, 9 insertions, 72 deletions
diff --git a/src/guile_type_helpers.c b/src/guile_type_helpers.c
index 072ddff9..2864df0d 100644
--- a/src/guile_type_helpers.c
+++ b/src/guile_type_helpers.c
@@ -3,13 +3,9 @@
#include "macro.h"
SCM scm_from_strbuf(strbuf* s) {
- // if (s->scm == NULL) {
- SCM ret = scm_from_utf8_stringn (s->mem, s->len);
- scm_gc_protect_object(ret);
- // }
-
- // return s->scm;
- return ret;
+ SCM ret = scm_from_utf8_stringn (s->mem, s->len);
+ scm_gc_protect_object(ret);
+ return ret;
}
SCM scm_from_strbuf_symbol(strbuf* s) {
diff --git a/src/guile_type_helpers.h b/src/guile_type_helpers.h
index c936f45d..fe0e875a 100644
--- a/src/guile_type_helpers.h
+++ b/src/guile_type_helpers.h
@@ -3,10 +3,12 @@
#include <libguile.h>
-#include "calendar.h"
#include "strbuf.h"
#define SCM_IS_LIST(x) scm_is_true(scm_list_p(x))
+#define string_eq(a, b) \
+ scm_is_true(scm_string_eq(a, b, \
+ SCM_UNDEFINED,SCM_UNDEFINED,SCM_UNDEFINED,SCM_UNDEFINED))
SCM scm_from_strbuf(strbuf* s);
SCM scm_from_strbuf_symbol(strbuf* s);
diff --git a/src/parse.c b/src/parse.c
index 3a5907c8..586a43b4 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -5,7 +5,6 @@
#include <assert.h>
#include "macro.h"
-// #include "vcal.h"
#include "err.h"
@@ -13,17 +12,6 @@
#include "struct.h"
#include "guile_type_helpers.h"
-// #define TYPE vcomponent
-// #include "linked_list.inc.h"
-// #undef TYPE
-
-// #define T strbuf
-// #define V strbuf
-// #include "pair.h"
-// #include "pair.inc.h"
-// #undef T
-// #undef V
-
/*
+-------------------------------------------------------+
v |
@@ -42,7 +30,6 @@
*/
-#define string_eq(a, b) scm_is_true(scm_string_eq(a, b, SCM_UNDEFINED,SCM_UNDEFINED,SCM_UNDEFINED,SCM_UNDEFINED))
/*
* name *(";" param) ":" value CRLF
@@ -52,26 +39,12 @@ 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);
-
- /*
- * Create a content_line which we use as storage while we are
- * parsing. This object is constantly broken down and rebuilt.
- *
- * {cline,param}_key is also temporary register used during
- * parsing.
- */
- // SNEW(content_line, cline);
- // SNEW(strbuf, param_key);
- // SNEW(strbuf, param_val);
- // SNEW(strbuf, attr_key);
- // SNEW(strbuf, attr_val);
SNEW(strbuf, str);
SCM component = root;
SCM line = scm_make_vline(SCM_UNDEFINED);
SCM attr_key; /* string */
- SCM line_key = scm_from_utf8_string(""); /* string */
+ SCM line_key = scm_from_utf8_string("");
SCM scm_filename = scm_from_utf8_stringn(filename, strlen(filename));
SCM filename_key = scm_from_utf8_string("X-HNH-FILENAME");
@@ -82,13 +55,12 @@ int parse_file(char* filename, FILE* f, SCM root) {
if (c == '\r' || c == '\n') {
if (fold(&ctx, c) > 0) {
/* Actuall end of line, handle value */
- // TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str);
/*
* The key being BEGIN means that we decend into a new component.
*/
if (string_eq(line_key, scm_from_utf8_string("BEGIN"))) {
/* key \in { VCALENDAR, VEVENT, VALARM, VTODO, VTIMEZONE, ... } */
- SCM child = scm_make_vcomponent(scm_string_to_symbol(scm_from_strbuf(&str)));
+ SCM child = scm_make_vcomponent(scm_from_strbuf_symbol(&str));
scm_add_child_x (component, child);
scm_add_line_x(child, filename_key, scm_make_vline(scm_filename));
@@ -186,16 +158,8 @@ int parse_file(char* filename, FILE* f, SCM root) {
}
- // FREE(content_line)(&cline);
- // FREE(strbuf)(&cline_key);
- // FREE(strbuf)(&param_key);
-
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));
-
FREE(parse_ctx)(&ctx);
return 0;
@@ -236,8 +200,6 @@ 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);
self->filename = (char*) calloc(sizeof(*filename), strlen(filename) + 1);
strcpy(self->filename, filename);
self->f = f;
@@ -248,20 +210,15 @@ INIT_F(parse_ctx, FILE* f, char* filename) {
self->pline = 1;
self->pcolumn = 1;
- // INIT(strbuf, &self->str);
-
return 0;
}
FREE_F(parse_ctx) {
- // FREE(LLIST(strbuf))(&self->key_stack);
- // FREE(LLIST(vcomponent))(&self->comp_stack);
free(self->filename);
self->line = 0;
self->column = 0;
- // FREE(strbuf)(&self->str);
return 0;
}
@@ -302,10 +259,6 @@ char handle_escape (parse_ctx* ctx) {
++ctx->column;
++ctx->pcolumn;
+ /* Returns the escaped char, for appending to the current string */
return esc;
-
- /* save escapade character as a normal character */
- // strbuf_append(&ctx->str, esc);
-
- // return 0;
}
diff --git a/src/parse.h b/src/parse.h
index a5169dd7..898abe5b 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -47,13 +47,6 @@ typedef struct {
FILE* f;
- /*
- * context stacks used since ICS files form a tree. key_stack is
- * only for sequrity purposes.
- */
- // LLIST(strbuf) key_stack;
- // LLIST(vcomponent) comp_stack;
-
/* Number for unfolded lines
* TODO remove this
* */
@@ -64,11 +57,6 @@ typedef struct {
int pline;
int pcolumn;
- /*
- * String which we write everything read into.
- * Later copied to appropiate places.
- */
- // strbuf str;
} parse_ctx;
INIT_F(parse_ctx, FILE* f, char* filename);
diff --git a/src/struct.scm.c b/src/struct.scm.c
index a8e7b3c6..051faf63 100644
--- a/src/struct.scm.c
+++ b/src/struct.scm.c
@@ -81,8 +81,6 @@ SCM_DEFINE(scm_add_attribute_x, "add-attribute!", 3, 0, 0,
}
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");
vcomponent_vtable = scm_make_vtable(str, SCM_BOOL_F);
scm_set_struct_vtable_name_x (vcomponent_vtable, scm_from_utf8_symbol("vcomponent"));