aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-19 11:17:16 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-19 11:17:16 +0100
commitfc5512ffa6091544d8e310ab7b7876f05f73f2de (patch)
treec9a8248c38e265dee748515dcdc5f7d02be5c02f
parentNow it links, but segfaults. (diff)
downloadcalp-fc5512ffa6091544d8e310ab7b7876f05f73f2de.tar.gz
calp-fc5512ffa6091544d8e310ab7b7876f05f73f2de.tar.xz
Jag kan inte ens programmera på rätt dator...
-rw-r--r--linked_list.h15
-rw-r--r--main.cpp2
-rw-r--r--parse.cpp27
-rw-r--r--vcal.cpp2
-rw-r--r--vcal.h3
5 files changed, 28 insertions, 21 deletions
diff --git a/linked_list.h b/linked_list.h
index 7ed4c6c4..75096a93 100644
--- a/linked_list.h
+++ b/linked_list.h
@@ -39,6 +39,8 @@ struct llist {
int size () { return length; }
bool empty () { return length == 0; }
+
+ void reset ();
};
template <typename T>
@@ -72,6 +74,19 @@ void llist<T>::push(T* val) {
this->__cur = l;
}
+template <typename T>
+void llist<T>::reset () {
+ llink<T> *link = this->first, *next;
+
+ while (link != this->tail) {
+ next = link->after;
+ delete link;
+ link = next;
+ }
+
+ this->__cur = this->head;
+}
+
// template <typename T>
// std::ostream& std::operator<<(std::ostream&, llist<T>);
diff --git a/main.cpp b/main.cpp
index 1e2c960e..d41fa258 100644
--- a/main.cpp
+++ b/main.cpp
@@ -23,7 +23,7 @@ int arg_shift (arg* a) {
}
int main (int argc, char** argv) {
- arg args = { .argc = argc, .argv = argv };
+ arg args = { argc, argv };
if (arg_shift(&args) == 0) {
ERR("Please give vdir or a vcalendar file as first argument");
diff --git a/parse.cpp b/parse.cpp
index 8d47ee72..df5aa053 100644
--- a/parse.cpp
+++ b/parse.cpp
@@ -64,7 +64,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
}
}
- /* Escaped new_line */
+ /* Escaped newline */
if (esc == 'n' || esc == 'N') {
target = '\n';
@@ -78,7 +78,6 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
}
/* save escapade character as a normal character */
- // strbuf_append(&ctx.str, target);
ctx.str += target;
++ctx.column;
@@ -87,20 +86,10 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
/* Border between param {key, value} */
} else if (p_ctx == p_param_name && c == '=') {
- // LLIST(param_set)* params = CLINE_CUR_PARAMS(&cline);
- /*
- std::list<param_set>* params = cline.val.val;
-
- // NEW(param_set, ps);
- auto ps = new param_set;
- // TODO make sure this is a deep copy
- ps->first = ctx.str;
- ps->first.cap();
+ strbuf cpy = ctx.str;
+ cpy.cap();
ctx.str.soft_reset();
- params += ps;
- // PUSH(LLIST(param_set))(params, ps);
- *
- */
+ cline.push_param_key (cpy);
p_ctx = p_param_value;
@@ -116,7 +105,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
if (p_ctx == p_param_value) {
/* push kv pair */
- auto s = new strbuf(ctx.str);;
+ auto s = new strbuf(ctx.str);
s->cap();
ctx.str.soft_reset();
@@ -124,10 +113,11 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
}
if (p_ctx == p_key) {
- // cline.first = ctx.str;
- // cline.first.cap();
+ cline.key = ctx.str;
+ cline.key.cap();
ctx.str.soft_reset();
+ // TODO?
// content_set* p = new content_set;
// cline.second.push(p);
}
@@ -190,6 +180,7 @@ int handle_kv (
*s = *type;
ctx->key_stack.push(s);
+ cline->values.reset();
// TODO ompty cline->second here;
// RESET(LLIST(content_set))(&cline->val);
diff --git a/vcal.cpp b/vcal.cpp
index 8180cf80..b0ce2c82 100644
--- a/vcal.cpp
+++ b/vcal.cpp
@@ -8,7 +8,7 @@ vcomponent::vcomponent(
const std::string& filename)
: type(type)
, filename(filename)
-{ };
+{ }
std::ostream& operator<<(std::ostream& o, vcomponent* self) {
for (int i = 0; i < 40; i++) o << '_';
diff --git a/vcal.h b/vcal.h
index fb767820..93699a29 100644
--- a/vcal.h
+++ b/vcal.h
@@ -40,7 +40,8 @@ struct content_line {
this->values.cur()->params.push(p);
}
- inline void push_param_value (strbuf* value) { this->values.cur()->params.cur()->values.push(value); }
+ inline void push_param_value (strbuf* value)
+ { this->values.cur()->params.cur()->values.push(value); }
inline strbuf* value() { return &this->values.cur()->value; }