From c374807e9d73014ce57eacbbaa56e05460288368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 9 Feb 2019 00:19:58 +0100 Subject: Extend parsing to handle tree's of vcomponents. --- linked_list.inc.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'linked_list.inc.h') 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); -- cgit v1.2.3