aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-19 12:08:03 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-19 12:08:03 +0100
commit86cb382c91fa965ad84d97c8c8e21957e695a1ae (patch)
tree88b5fc4e4eac2554a31485342d2d1c8bc5255075
parentJag kan inte ens programmera på rätt dator... (diff)
downloadcalp-86cb382c91fa965ad84d97c8c8e21957e695a1ae.tar.gz
calp-86cb382c91fa965ad84d97c8c8e21957e695a1ae.tar.xz
Further changes.
-rw-r--r--Makefile2
-rw-r--r--linked_list.cpp59
-rw-r--r--linked_list.h47
-rw-r--r--parse.cpp15
-rw-r--r--vcal.h2
5 files changed, 53 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index e9c3140b..e5a0ae1a 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC := g++
OBJDIR = obj
-CFLAGS = -std=gnu++11 -Wall -Wextra -Wno-reorder \
+CFLAGS = -std=gnu++11 -pedantic -Wall -Wextra -Wno-reorder \
-ggdb -fPIC # \
# $(shell guile-config compile)
LDFLAGS = -fPIC # $(shell guile-config link)
diff --git a/linked_list.cpp b/linked_list.cpp
deleted file mode 100644
index ed37eb23..00000000
--- a/linked_list.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "linked_list.h"
-
-template <typename T>
-llink<T>::~llink () {
- this.unlink();
-}
-
-template <typename T>
-void llink<T>::unlink () {
- if (this->before != nullptr) this->before->after = this->after;
- if (this->after != nullptr) this->after->before = this->before;
-}
-
-template <typename T>
-T& llist<T>::peek() {
- if (this->empty()) return nullptr;
-
- return FIRST(this)->value;
-}
-
-template <typename T>
-T& llist<T>::pop() {
- if (this->empty()) return nullptr;
-
- llink<T>* frst = FIRST(this);
- frst.unlinke();
-
- T& retval = frst->value;
- --this->length;
- delete frst;
-
- return retval;
-}
-
-template <typename T>
-void llist<T>::operator+= (llist<T>& other) {
-
- /* Link end of dest onto start of new__. */
- LAST(this)->after = FIRST(other);
- FIRST(other)->before = LAST(this);
-
- /* Free the two now not needed end links. */
- delete other->head;
- delete other->tail;
-
- /* Update dest with new__ tail ptr. */
- this->tail = other->tail;
-
- this->length += other->length;
-}
-
-// template <typename T>
-// std::ostream& std::operator<<(std::ostream&, llist<T>) {
-// o << '(';
-// for (T t : list) {
-// o << t;
-// }
-// o << ')';
-// }
diff --git a/linked_list.h b/linked_list.h
index 75096a93..1d95de80 100644
--- a/linked_list.h
+++ b/linked_list.h
@@ -10,7 +10,7 @@ struct llink {
llink () { };
llink (T* val) : value(val) { }
- ~llink ();
+ ~llink () { this->unlink(); }
void unlink ();
};
@@ -76,7 +76,7 @@ void llist<T>::push(T* val) {
template <typename T>
void llist<T>::reset () {
- llink<T> *link = this->first, *next;
+ llink<T> *link = this->head, *next;
while (link != this->tail) {
next = link->after;
@@ -86,6 +86,49 @@ void llist<T>::reset () {
this->__cur = this->head;
}
+template <typename T>
+void llink<T>::unlink () {
+ if (this->before != nullptr) this->before->after = this->after;
+ if (this->after != nullptr) this->after->before = this->before;
+}
+
+template <typename T>
+T& llist<T>::peek() {
+ if (this->empty()) return nullptr;
+
+ return FIRST(this)->value;
+}
+
+template <typename T>
+T& llist<T>::pop() {
+ if (this->empty()) return nullptr;
+
+ llink<T>* frst = FIRST(this);
+ frst.unlinke();
+
+ T& retval = frst->value;
+ --this->length;
+ delete frst;
+
+ return retval;
+}
+
+template <typename T>
+void llist<T>::operator+= (llist<T>& other) {
+
+ /* Link end of dest onto start of new__. */
+ LAST(this)->after = FIRST(other);
+ FIRST(other)->before = LAST(this);
+
+ /* Free the two now not needed end links. */
+ delete other->head;
+ delete other->tail;
+
+ /* Update dest with new__ tail ptr. */
+ this->tail = other->tail;
+
+ this->length += other->length;
+}
// template <typename T>
// std::ostream& std::operator<<(std::ostream&, llist<T>);
diff --git a/parse.cpp b/parse.cpp
index df5aa053..1b186d4c 100644
--- a/parse.cpp
+++ b/parse.cpp
@@ -34,8 +34,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
// TODO solve current;
// std::string& target = cline
- strbuf target = ctx.str;
- target.cap();
+ cline.value() = ctx.str;
+ cline.value().cap();
ctx.str.soft_reset();
handle_kv(&cline, &ctx);
@@ -145,9 +145,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
*/
//strbuf* target = CLINE_CUR_VAL(&cline);
- strbuf* target = cline.value();
- *target = ctx.str;
- target->cap();
+ cline.value() = ctx.str;
+ cline.value().cap();
ctx.str.soft_reset();
++ctx.line;
@@ -175,9 +174,7 @@ int handle_kv (
* and possibly some others I forget.
*/
- strbuf* s = new strbuf;
- strbuf* type = cline->value();
- *s = *type;
+ strbuf* s = new strbuf(cline->value());
ctx->key_stack.push(s);
cline->values.reset();
@@ -191,7 +188,7 @@ int handle_kv (
} else if (cline->key == "END") {
// strbuf* s = POP(LLIST(strbuf))(&ctx->key_stack);
strbuf* s = ctx->key_stack.top(); ctx->key_stack.pop();
- if (s == cline->value()) {
+ if (*s == cline->value()) {
#if 0
ERR_P(ctx, "Expected END:%s, got END:%s.\n%s line",
s->mem,
diff --git a/vcal.h b/vcal.h
index 93699a29..ea76e593 100644
--- a/vcal.h
+++ b/vcal.h
@@ -43,7 +43,7 @@ struct content_line {
inline void push_param_value (strbuf* value)
{ this->values.cur()->params.cur()->values.push(value); }
- inline strbuf* value() { return &this->values.cur()->value; }
+ inline strbuf& value() { return this->values.cur()->value; }
};