diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-09 00:19:58 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-09 00:19:58 +0100 |
commit | c374807e9d73014ce57eacbbaa56e05460288368 (patch) | |
tree | af9974aa6b03c9e25c9e42c108d9f25277665b41 /linked_list.inc.h | |
parent | Fix minor memmory error. (diff) | |
download | calp-c374807e9d73014ce57eacbbaa56e05460288368.tar.gz calp-c374807e9d73014ce57eacbbaa56e05460288368.tar.xz |
Extend parsing to handle tree's of vcomponents.
Diffstat (limited to '')
-rw-r--r-- | linked_list.inc.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/linked_list.inc.h b/linked_list.inc.h index e91cdc9f..ada0b424 100644 --- a/linked_list.inc.h +++ b/linked_list.inc.h @@ -15,8 +15,7 @@ INIT_F ( LLIST(TYPE) ) { } FREE_F (LINK(TYPE)) { - if (this->before != NULL) this->before->after = NULL; - if (this->after != NULL) this->after->before = NULL; + UNLINK(LINK(TYPE))(this); if (this->value != NULL) FFREE(TYPE, this->value); return 0; @@ -50,6 +49,13 @@ INIT_F ( LINK(TYPE), TYPE* 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; + return 0; +} + + int PUSH(LLIST(TYPE)) ( LLIST(TYPE)* lst, TYPE* val) { NEW(LINK(TYPE), link, val); @@ -67,6 +73,23 @@ int PUSH(LLIST(TYPE)) ( LLIST(TYPE)* lst, TYPE* val) { return 0; } +TYPE* PEEK(LLIST(TYPE)) ( LLIST(TYPE)* lst ) { + if (EMPTY(LLIST(TYPE))(lst)) return NULL; + + return FIRST(lst)->value; +} + +TYPE* POP(LLIST(TYPE)) ( LLIST(TYPE)* lst) { + if (EMPTY(LLIST(TYPE))(lst)) return NULL; + + LINK(TYPE)* frst = FIRST(lst); + UNLINK(LINK(TYPE))(frst); + + TYPE* retval = frst->value; + free (frst); + return retval; +} + int DEEP_COPY(LLIST(TYPE)) ( LLIST(TYPE)* dest, LLIST(TYPE)* src ) { LINK(TYPE)* n = FIRST(src); |