aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-18 22:39:56 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-18 22:39:56 +0100
commit33fa5b5d0c512c72c1d50b9420a36431cd10eb5d (patch)
tree6642ec876ecd15ce62f83075d7f9d261050fe3a6
parentStart rework of guile interface. (diff)
downloadcalp-33fa5b5d0c512c72c1d50b9420a36431cd10eb5d.tar.gz
calp-33fa5b5d0c512c72c1d50b9420a36431cd10eb5d.tar.xz
Made to compile as C++.
-rw-r--r--Makefile4
-rw-r--r--guile_interface.h__ (renamed from guile_interface.h)0
-rw-r--r--guile_interface.scm.c__ (renamed from guile_interface.scm.c)2
-rw-r--r--guile_interface.x__6
-rw-r--r--guile_type_helpers.c__ (renamed from guile_type_helpers.c)0
-rw-r--r--guile_type_helpers.h__ (renamed from guile_type_helpers.h)0
-rw-r--r--hash.inc.h2
-rw-r--r--linked_list.h4
-rw-r--r--linked_list.inc.h64
-rw-r--r--macro.h16
-rw-r--r--main.c4
-rw-r--r--pair.inc.h12
-rw-r--r--parse.c40
-rw-r--r--strbuf.c34
-rw-r--r--strbuf.h2
-rw-r--r--trie.inc.h44
-rw-r--r--vcal.c50
-rw-r--r--vcal.h8
-rw-r--r--vector.inc.h40
19 files changed, 169 insertions, 163 deletions
diff --git a/Makefile b/Makefile
index 6daff1d4..0ae2ccc0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
.PHONY: all clean
-CC := gcc
+CC := g++
OBJDIR = obj
-CFLAGS = -std=gnu11 -Wall -Wextra \
+CFLAGS = -std=gnu++11 -Wall -Wextra \
-ggdb -fPIC \
$(shell guile-config compile)
LDFLAGS = -fPIC $(shell guile-config link)
diff --git a/guile_interface.h b/guile_interface.h__
index 91e25a72..91e25a72 100644
--- a/guile_interface.h
+++ b/guile_interface.h__
diff --git a/guile_interface.scm.c b/guile_interface.scm.c__
index 6aeeba66..e86504be 100644
--- a/guile_interface.scm.c
+++ b/guile_interface.scm.c__
@@ -63,7 +63,7 @@ SCM_DEFINE (vcomponent_child_count, "vcomponent-child-count", 1, 0, 0,
return scm_from_size_t (SIZE(VECT(vcomponent))(&c->components));
}
-/* TODO This currently returns a new foreign object each time I call it. */
+/* TODO This currently returns a new_ foreign object each time I call it. */
SCM_DEFINE(vcomponent_children, "vcomponent-children", 1, 0, 0,
(SCM component),
"")
diff --git a/guile_interface.x__ b/guile_interface.x__
new file mode 100644
index 00000000..badb3ca8
--- /dev/null
+++ b/guile_interface.x__
@@ -0,0 +1,6 @@
+/* cpp arguments: guile_interface.scm.c -std=gnu11 -Wall -Wextra -fPIC -pthread -I/usr/include/guile/2.2 */
+scm_c_define_gsubr (s_make_vcomponent, 1, 0, 0, (scm_t_subr) make_vcomponent);;
+scm_c_define_gsubr (s_vcomponent_get_attribute, 2, 0, 0, (scm_t_subr) vcomponent_get_attribute);;
+scm_c_define_gsubr (s_vcomponent_child_count, 1, 0, 0, (scm_t_subr) vcomponent_child_count);;
+scm_c_define_gsubr (s_vcomponent_children, 1, 0, 0, (scm_t_subr) vcomponent_children);;
+scm_c_define_gsubr (s_vcomponent_typeof, 1, 0, 0, (scm_t_subr) vcomponent_typeof);;
diff --git a/guile_type_helpers.c b/guile_type_helpers.c__
index 3f76c2d4..3f76c2d4 100644
--- a/guile_type_helpers.c
+++ b/guile_type_helpers.c__
diff --git a/guile_type_helpers.h b/guile_type_helpers.h__
index bb69312d..bb69312d 100644
--- a/guile_type_helpers.h
+++ b/guile_type_helpers.h__
diff --git a/hash.inc.h b/hash.inc.h
index 0aee8ef4..0945dfc4 100644
--- a/hash.inc.h
+++ b/hash.inc.h
@@ -1,5 +1,5 @@
#ifndef TYPE
-#error "Set TYPE to something before including this header"
+#error "Set TYPE to something before including self header"
#else
#include "err.h"
diff --git a/linked_list.h b/linked_list.h
index 909a38a8..a17bd797 100644
--- a/linked_list.h
+++ b/linked_list.h
@@ -52,7 +52,7 @@ 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 APPEND(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* new_ );
int SIZE(LLIST(TYPE)) ( LLIST(TYPE)* llist );
int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist );
@@ -63,7 +63,7 @@ int EMPTY(LLIST(TYPE)) ( LLIST(TYPE)* llist );
*/
int RESET(LLIST(TYPE)) ( LLIST(TYPE)* llist );
-LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new);
+LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new_);
FMT_F(LLIST(TYPE));
diff --git a/linked_list.inc.h b/linked_list.inc.h
index cb6df29c..8ae720ba 100644
--- a/linked_list.inc.h
+++ b/linked_list.inc.h
@@ -1,57 +1,57 @@
#ifndef TYPE
-#error "Set TYPE before including this file"
+#error "Set TYPE before including self file"
#else
INIT_F ( LLIST(TYPE) ) {
- this->length = 0;
+ self->length = 0;
NEW(LINK(TYPE), head);
NEW(LINK(TYPE), tail);
- this->head = head;
- this->tail = tail;
+ self->head = head;
+ self->tail = tail;
head->after = tail;
tail->before = head;
- this->cur = head;
+ self->cur = head;
return 0;
}
FREE_F (LINK(TYPE)) {
- UNLINK(LINK(TYPE))(this);
+ UNLINK(LINK(TYPE))(self);
- if (this->value != NULL) FFREE(TYPE, this->value);
+ if (self->value != NULL) FFREE(TYPE, self->value);
return 0;
}
FREE_F( LLIST(TYPE) ) {
LINK(TYPE) *n, *next;
- n = this->head;
+ n = self->head;
while ( n != NULL ) {
next = n->after;
FFREE(LINK(TYPE), n);
n = next;
}
- this->length = -1;
+ self->length = -1;
return 0;
}
INIT_F ( LINK(TYPE) ) {
- this->before = NULL;
- this->after = NULL;
- this->value = NULL;
+ self->before = NULL;
+ self->after = NULL;
+ self->value = NULL;
return 0;
}
INIT_F ( LINK(TYPE), TYPE* val ) {
- this->before = NULL;
- this->after = NULL;
- this->value = val;
+ self->before = NULL;
+ self->after = NULL;
+ self->value = val;
return 0;
}
-int UNLINK(LINK(TYPE)) ( LINK(TYPE)* this ) {
- if (this->before != NULL) this->before->after = this->after;
- if (this->after != NULL) this->after->before = this->before;
+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;
}
@@ -107,23 +107,23 @@ int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ) {
/*
* Adds two linked lists together.
* O(1) time.
- * destroys new in the process, but keeps the elements.
- * make sure to free(new) after.
+ * 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 ) {
+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);
+ /* 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(new__->head);
free(dest->tail);
- /* Update dest with new tail ptr. */
- dest->tail = new->tail;
+ /* Update dest with new__ tail ptr. */
+ dest->tail = new__->tail;
- dest->length += new->length;
+ dest->length += new__->length;
return 0;
}
@@ -136,9 +136,9 @@ 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);
+LLIST(TYPE)* RESOLVE(LLIST(TYPE)) (LLIST(TYPE)* dest, LLIST(TYPE)* new__) {
+ if (dest == NULL) return new__;
+ APPEND(LLIST(TYPE))(dest, new__);
return dest;
}
@@ -163,7 +163,7 @@ int RESET(LLIST(TYPE)) ( LLIST(TYPE)* llist ) {
FMT_F(LLIST(TYPE)) {
int seek = 0;
fmtf("(");
- FOR(LLIST, TYPE, v, this) {
+ FOR(LLIST, TYPE, v, self) {
seek += FMT(TYPE)(v, buf + seek);
fmtf(" ");
}
diff --git a/macro.h b/macro.h
index 5762eee6..6421b2fd 100644
--- a/macro.h
+++ b/macro.h
@@ -40,31 +40,31 @@
/* Returns full type of constructor */
#define INIT_F(T, ...) \
- int __INIT_T(T, VA_ARGS_NUM(__VA_ARGS__)) (T* this, ## __VA_ARGS__)
+ int __INIT_T(T, VA_ARGS_NUM(__VA_ARGS__)) (T* self, ## __VA_ARGS__)
/*
* Call the constructor of an object
- * `int` part of the macro, to ensure that any attempt to call this
+ * `int` part of the macro, to ensure that any attempt to call self
* function results in an error.
*/
#define INIT(T, N, ...) \
__INIT_T(T, VA_ARGS_NUM(__VA_ARGS__)) (N, ## __VA_ARGS__)
-/* Allocate a new object on the HEAP */
+/* Allocate a new_ object on the HEAP */
#define NEW(T, N, ...) \
- T* N = malloc(sizeof(*N)); \
+ T* N = (T*) malloc(sizeof(*N)); \
INIT(T, N, ## __VA_ARGS__);
/*
* Reconstructs a object. Use with caution.
*/
#define RENEW(T, N, ...) do { \
- N = malloc(sizeof(*N)); \
+ N = (T*) malloc(sizeof(*N)); \
INIT(T, N, ## __VA_ARGS__); \
} while (0)
-/* Allocate a new object on the STACK */
+/* Allocate a new_ object on the STACK */
#define SNEW(T, N, ...) \
T N; \
INIT(T, & N, ## __VA_ARGS__);
@@ -76,7 +76,7 @@
#define FFREE(T, N) do { FREE(T)(N); free(N); } while (0)
/* Declare destructor */
-#define FREE_F(T) int FREE(T) (T* this)
+#define FREE_F(T) int FREE(T) (T* self)
/* generate reusable internal symbol */
#define __INTER(s) TP3(__, s, __internal)
@@ -122,7 +122,7 @@
*/
#define FMT_T(T) TEMPL(format , T)
-#define FMT_F(T) int FMT_T(T)(T* this, char* buf, ...)
+#define FMT_F(T) int FMT_T(T)(T* self, char* buf, ...)
// TODO change order of buf and item
#define __FMT_HELP(item, buf, ...) ((item), (buf), VA_ARGS_NUM(__VA_ARGS__), ## __VA_ARGS__)
#define FMT(T) FMT_T(T) __FMT_HELP
diff --git a/main.c b/main.c
index ec8041a5..830eb538 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@ int arg_shift (arg* a) {
}
-int main (int argc, char* argv[argc]) {
+int main (int argc, char** argv) {
arg args = { .argc = argc, .argv = argv };
if (arg_shift(&args) == 0) {
@@ -62,7 +62,7 @@ int main (int argc, char* argv[argc]) {
}
}
} else if (strcmp(args.argv[0], "-g") == 0) {
- /* TODO this might be broken */
+ /* 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);
diff --git a/pair.inc.h b/pair.inc.h
index 5f746f1b..c42b2dfd 100644
--- a/pair.inc.h
+++ b/pair.inc.h
@@ -3,15 +3,15 @@
#else
INIT_F(PAIR(T, V)) {
- INIT(T, &this->key);
- INIT(V, &this->val);
+ INIT(T, &self->key);
+ INIT(V, &self->val);
return 0;
}
FREE_F(PAIR(T, V)) {
- FREE(T)(&this->key);
- FREE(V)(&this->val);
+ FREE(T)(&self->key);
+ FREE(V)(&self->val);
return 0;
}
@@ -19,8 +19,8 @@ FREE_F(PAIR(T, V)) {
FMT_F(PAIR(T, V)) {
char lbuf[0x100];
char rbuf[0x1000];
- FMT(T)(&this->key, lbuf);
- FMT(V)(&this->val, rbuf);
+ FMT(T)(&self->key, lbuf);
+ FMT(V)(&self->val, rbuf);
return sprintf(buf, "<%s, %s>", lbuf, rbuf);
}
diff --git a/parse.c b/parse.c
index 98d847a1..8f7a9102 100644
--- a/parse.c
+++ b/parse.c
@@ -72,7 +72,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
}
}
- /* Escaped newline */
+ /* Escaped new_line */
if (esc == 'n' || esc == 'N') {
target = '\n';
@@ -220,7 +220,7 @@ int handle_kv (
/* Received propper end, push cur into parent */
vcomponent* cur = POP(LLIST(vcomponent))(&ctx->comp_stack);
- // TODO should this instead be done at creation time?
+ // TODO should self instead be done at creation time?
PUSH(vcomponent)(PEEK(LLIST(vcomponent))(&ctx->comp_stack), cur);
}
} else {
@@ -241,14 +241,14 @@ int fold(FILE* f, parse_ctx* ctx, char c) {
int retval;
char buf[2] = {
- (c == '\n' ? '\n' : fgetc(f)),
- fgetc(f)
+ (c == '\n' ? '\n' : (char) fgetc(f)),
+ (char) fgetc(f)
};
ctx->pcolumn = 1;
if (buf[0] != '\n') {
- ERR_P(ctx, "expected newline after CR");
+ ERR_P(ctx, "expected new_line after CR");
retval = -1;
} else if (buf[1] == ' ' || buf[1] == '\t') {
@@ -272,31 +272,31 @@ int fold(FILE* f, parse_ctx* ctx, char c) {
INIT_F(parse_ctx, char* filename) {
- INIT(LLIST(strbuf), &this->key_stack);
- INIT(LLIST(vcomponent), &this->comp_stack);
- this->filename = calloc(sizeof(*filename), strlen(filename) + 1);
- strcpy(this->filename, 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);
- this->line = 0;
- this->column = 0;
+ self->line = 0;
+ self->column = 0;
- this->pline = 1;
- this->pcolumn = 1;
+ self->pline = 1;
+ self->pcolumn = 1;
- INIT(strbuf, &this->str);
+ INIT(strbuf, &self->str);
return 0;
}
FREE_F(parse_ctx) {
- FREE(LLIST(strbuf))(&this->key_stack);
- FREE(LLIST(vcomponent))(&this->comp_stack);
- free(this->filename);
+ FREE(LLIST(strbuf))(&self->key_stack);
+ FREE(LLIST(vcomponent))(&self->comp_stack);
+ free(self->filename);
- this->line = 0;
- this->column = 0;
- FREE(strbuf)(&this->str);
+ self->line = 0;
+ self->column = 0;
+ FREE(strbuf)(&self->str);
return 0;
}
diff --git a/strbuf.c b/strbuf.c
index 7193b134..f17de211 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -6,7 +6,7 @@
#include "err.h"
INIT_F(strbuf) {
- INIT(strbuf, this, 1);
+ INIT(strbuf, self, 1);
return 0;
}
@@ -14,27 +14,27 @@ INIT_F(strbuf) {
* Giving len < 1 is an error.
*/
INIT_F(strbuf, size_t len) {
- this->mem = calloc(sizeof(*this->mem), len);
- this->alloc = len;
- this->ptr = 0;
- this->len = 0;
+ self->mem = (char*) calloc(sizeof(*self->mem), len);
+ self->alloc = len;
+ self->ptr = 0;
+ self->len = 0;
return 0;
}
int strbuf_realloc(strbuf* str, size_t len) {
- str->mem = realloc(str->mem, len);
+ str->mem = (char*) realloc(str->mem, len);
str->alloc = len;
return 0;
}
FREE_F(strbuf) {
/* has already been freed */
- if (this->mem == NULL) return 1;
+ if (self->mem == NULL) return 1;
- free (this->mem);
- this->mem = NULL;
- this->alloc = 0;
- this->len = 0;
+ free (self->mem);
+ self->mem = NULL;
+ self->alloc = 0;
+ self->len = 0;
return 0;
}
@@ -46,7 +46,7 @@ int strbuf_append(strbuf* s, char c) {
if (s->len + 1 > s->alloc) {
s->alloc <<= 1;
- s->mem = realloc(s->mem, s->alloc);
+ s->mem = (char*) realloc(s->mem, s->alloc);
retval = 1;
}
@@ -124,15 +124,15 @@ int strbuf_soft_reset(strbuf* s) {
return 0;
}
-strbuf* RESOLVE(strbuf)(strbuf* dest, strbuf* new) {
- if (dest == NULL) return new;
+strbuf* RESOLVE(strbuf)(strbuf* dest, strbuf* new_) {
+ if (dest == NULL) return new_;
else return dest;
}
FMT_F(strbuf) {
- return sprintf(buf, "%s", this->mem);
+ return sprintf(buf, "%s", self->mem);
}
-int SIZE(strbuf)(strbuf* this) {
- return this->len;
+int SIZE(strbuf)(strbuf* self) {
+ return self->len;
}
diff --git a/strbuf.h b/strbuf.h
index fcbb7e74..c531734e 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -92,7 +92,7 @@ int strbuf_realloc_copy(strbuf* dest, strbuf* src);
/*
* Copies contents from src to dest, also allocating dest in the
- * process. dest should not be initialized before this call.
+ * process. dest should not be initialized before self call.
*/
int strbuf_init_copy(strbuf* dest, strbuf* src);
diff --git a/trie.inc.h b/trie.inc.h
index 3ac9acac..5517939e 100644
--- a/trie.inc.h
+++ b/trie.inc.h
@@ -1,5 +1,5 @@
#ifndef TYPE
-#error "Set TYPE before including this file"
+#error "Set TYPE before including self file"
#else
#include <stdarg.h>
@@ -9,15 +9,15 @@
INIT_F ( TRIE(TYPE) ) {
NEW(TRIE_NODE(TYPE), t, '\0');
- this->root = t;
+ self->root = t;
return 0;
}
INIT_F (TRIE_NODE(TYPE), char c) {
- this->c = c;
- this->value = NULL;
- this->next = NULL;
- this->child = NULL;
+ self->c = c;
+ self->value = NULL;
+ self->next = NULL;
+ self->child = NULL;
return 0;
}
@@ -26,9 +26,9 @@ INIT_F (TRIE_NODE(TYPE),
TRIE_NODE(TYPE)* next,
TRIE_NODE(TYPE)* child )
{
- this->c = c;
- this->next = next;
- this->child = child;
+ self->c = c;
+ self->next = next;
+ self->child = child;
return 0;
}
@@ -65,7 +65,7 @@ int PUSH(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key, TYPE* val ) {
cur = cur->next;
/* `last` not set since we aren't moving down */
} else {
- /* No node on this level was part of the set, create a new
+ /* 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;
@@ -100,24 +100,24 @@ TYPE* GET(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key ) {
}
FREE_F(TRIE_NODE(TYPE)) {
- if (this == NULL) return 0;
- if (this->value != NULL) FFREE(TYPE, this->value);
- if (this->next != NULL) FREE(TRIE_NODE(TYPE))(this->next);
- if (this->child != NULL) FREE(TRIE_NODE(TYPE))(this->child);
- free (this);
+ 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 (this->root->c != '\0') {
+ if (self->root->c != '\0') {
// ERR("Invalid trie");
return 1;
}
- return FREE(TRIE_NODE(TYPE))(this->root);
+ return FREE(TRIE_NODE(TYPE))(self->root);
}
-int EMPTY(TRIE(TYPE))(TRIE(TYPE)* this) {
- return this->root->child == NULL;
+int EMPTY(TRIE(TYPE))(TRIE(TYPE)* self) {
+ return self->root->child == NULL;
}
FMT_F(TRIE_NODE(TYPE)) {
@@ -132,7 +132,7 @@ FMT_F(TRIE_NODE(TYPE)) {
int seek = 0;
- TRIE_NODE(TYPE)* n = this;
+ TRIE_NODE(TYPE)* n = self;
if (n == NULL) { fmtf("\n"); }
while (n != NULL) {
@@ -157,8 +157,8 @@ FMT_F(TRIE_NODE(TYPE)) {
FMT_F(TRIE(TYPE)) {
int seek = 0;
- fmtf("Trie: %p: {\n", this);
- seek += FMT(TRIE_NODE(TYPE))(this->root->child, buf + seek);
+ fmtf("Trie: %p: {\n", self);
+ seek += FMT(TRIE_NODE(TYPE))(self->root->child, buf + seek);
fmtf("}");
return seek;
}
diff --git a/vcal.c b/vcal.c
index 3961d5d6..7f674dac 100644
--- a/vcal.c
+++ b/vcal.c
@@ -36,49 +36,49 @@
#undef TYPE
INIT_F(vcomponent) {
- (void) this;
+ (void) self;
ERR("Do not use");
return 0;
}
INIT_F(vcomponent, char* type) {
- return INIT(vcomponent, this, type, NULL);
+ return INIT(vcomponent, self, type, NULL);
}
INIT_F(vcomponent, char* type, char* filename) {
- INIT(TRIE(content_line), &this->clines);
- INIT(VECT(vcomponent), &this->components);
+ INIT(TRIE(content_line), &self->clines);
+ INIT(VECT(vcomponent), &self->components);
- this->filename = NULL;
+ self->filename = NULL;
if (filename != NULL) {
- this->filename = calloc(sizeof(*filename), strlen(filename) + 1);
- strcpy(this->filename, filename);
+ self->filename = (char*) calloc(sizeof(*filename), strlen(filename) + 1);
+ strcpy(self->filename, filename);
}
- this->type = calloc(sizeof(*type), strlen(type) + 1);
- strcpy(this->type, type);
+ self->type = (char*) calloc(sizeof(*type), strlen(type) + 1);
+ strcpy(self->type, type);
- this->parent = NULL;
+ self->parent = NULL;
return 0;
}
content_line* RESOLVE(content_line)
- (content_line* dest, content_line* new)
+ (content_line* dest, content_line* new_)
{
- if (dest == NULL) return new;
+ if (dest == NULL) return new_;
- if (strbuf_cmp(&dest->key, &new->key) != 0) {
+ if (strbuf_cmp(&dest->key, &new_->key) != 0) {
ERR("Can't resolve between these two types");
return NULL;
}
- /* This destroys new->val. */
- APPEND(LLIST(content_set)) (&dest->val, &new->val);
+ /* This destroys new_->val. */
+ APPEND(LLIST(content_set)) (&dest->val, &new_->val);
- FREE(strbuf)(&new->key);
- free(new);
+ FREE(strbuf)(&new_->key);
+ free(new_);
return dest;
}
@@ -88,15 +88,15 @@ content_line* get_property (vcomponent* ev, char* key) {
}
FREE_F(vcomponent) {
- if (this->filename != NULL) free(this->filename);
- free(this->type);
+ if (self->filename != NULL) free(self->filename);
+ free(self->type);
- if (FREE(TRIE(content_line))(&this->clines) != 0) {
+ if (FREE(TRIE(content_line))(&self->clines) != 0) {
fprintf(stderr, "Error freeing vcomponent belonging to file \n %s \n",
- this->filename);
+ self->filename);
}
- FREE(VECT(vcomponent))(&this->components);
+ FREE(VECT(vcomponent))(&self->components);
return 0;
}
@@ -118,11 +118,11 @@ FMT_F(vcomponent) {
for (int i = 0; i < 40; i++) fmtf("_");
seek += sprintf(buf + seek, _YELLOW);
- seek += sprintf(buf + seek, "\nVComponet (Type := %s)\n", this->type);
+ seek += sprintf(buf + seek, "\nVComponet (Type := %s)\n", self->type);
seek += sprintf(buf + seek, _RESET);
- seek += FMT(TRIE(content_line))(&this->clines, buf + seek);
+ seek += FMT(TRIE(content_line))(&self->clines, buf + seek);
seek += sprintf(buf + seek, "\nComponents:\n");
- FOR(VECT, vcomponent, comp, &this->components) {
+ FOR(VECT, vcomponent, comp, &self->components) {
seek += FMT(vcomponent)(comp, buf + seek);
}
diff --git a/vcal.h b/vcal.h
index 21358cb6..1c96c4c6 100644
--- a/vcal.h
+++ b/vcal.h
@@ -46,7 +46,7 @@
* Helper macros for accessing fields in
* content_line, content_set, and param_set
*
- * TODO find a better way to do this.
+ * TODO find a better way to do self.
*/
/* ptr -> ptr */
@@ -68,12 +68,12 @@
/*
* Resolves a collision in some form of structure (probably a hash-map
- * or a trie). If dest is NULL just return new. Otherwise mutates dest
- * to have the correct form, and returns it. Destroying new in the
+ * or a trie). If dest is NULL just return new_. Otherwise mutates dest
+ * to have the correct form, and returns it. Destroying new_ in the
* process.
*/
content_line* RESOLVE(content_line)
- (content_line* dest, content_line* new);
+ (content_line* dest, content_line* new_);
#define TYPE content_line
#include "trie.h"
diff --git a/vector.inc.h b/vector.inc.h
index f6d1c796..2b23eadc 100644
--- a/vector.inc.h
+++ b/vector.inc.h
@@ -1,51 +1,51 @@
#ifndef TYPE
-#error "Set TYPE before including this file"
+#error "Set TYPE before including self file"
#else
#include "macro.h"
#include "err.h"
INIT_F(VECT(TYPE)) {
- this->length = 0;
- this->alloc = 1;
- this->items = calloc(sizeof(*this->items), this->alloc);
+ 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 < this->length; i++) {
- FFREE(TYPE, this->items[i]);
+ for (unsigned int i = 0; i < self->length; i++) {
+ FFREE(TYPE, self->items[i]);
}
- free(this->items);
+ free(self->items);
return 0;
}
-int PUSH(VECT(TYPE))(VECT(TYPE)* this, TYPE* t) {
- if (this->length + 1 > this->alloc) {
- this->alloc <<= 1;
- this->items = realloc(this->items, sizeof(*this->items) * this->alloc);
+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);
}
- this->items[this->length] = t;
- ++this->length;
+ self->items[self->length] = t;
+ ++self->length;
return 0;
}
-TYPE* GET(VECT(TYPE))(VECT(TYPE)* this, unsigned int idx) {
- if (idx >= this->length) {
+TYPE* GET(VECT(TYPE))(VECT(TYPE)* self, unsigned int idx) {
+ if (idx >= self->length) {
ERR("Index out of range");
return NULL;
}
- return this->items[idx];
+ return self->items[idx];
}
-int EMPTY(VECT(TYPE))(VECT(TYPE)* this) {
- return this->length == 0;
+int EMPTY(VECT(TYPE))(VECT(TYPE)* self) {
+ return self->length == 0;
}
-unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* this) {
- return this->length;
+unsigned int SIZE(VECT(TYPE))(VECT(TYPE)* self) {
+ return self->length;
}
#endif /* TYPE */