From e9491f341f12bb8e5fee267ea6106ff52c9328df Mon Sep 17 00:00:00 2001 From: khamidou Date: Mon, 2 Mar 2009 18:51:12 +0100 Subject: [PATCH] implemented foreach() at last --- macro.c | 12 ++++++++++++ macro.h | 3 ++- parse.c | 8 ++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/macro.c b/macro.c index 41c60ed..9786d46 100644 --- a/macro.c +++ b/macro.c @@ -37,4 +37,16 @@ void free_block(struct croma_block *b) free(b->contents); free(b->name); TAILQ_REMOVE(&blocks_head, b, blocks); + free(b); +} + +void free_arg(struct croma_block *b, struct croma_arg *a) +{ + if (b == NULL) + return; + + TAILQ_REMOVE(&b->args_head, a, params); + free(a->name); + free(a->value); + free(a); } diff --git a/macro.h b/macro.h index d9f904b..1a1a827 100644 --- a/macro.h +++ b/macro.h @@ -30,7 +30,7 @@ struct croma_block { }; /* - blocks_head is our symbol tab. + blocks_head is our symbol table. */ TAILQ_HEAD(croma_blocks_head, croma_block) blocks_head; @@ -42,5 +42,6 @@ TAILQ_HEAD(croma_blocks_head, croma_block) blocks_head; struct croma_block* alloc_and_insert_block(void); struct croma_arg *alloc_and_insert_arg(struct croma_block *b); void free_block(struct croma_block *b); +void free_arg(struct croma_block *b, struct croma_arg *a); #endif diff --git a/parse.c b/parse.c index 0163b7a..89a3835 100644 --- a/parse.c +++ b/parse.c @@ -66,10 +66,7 @@ void yyparse(void) void foreach_expr(void) { - struct croma_block *b = malloc(sizeof(struct croma_block)); - - if (b == NULL) - fail("Unable to alloc() memory"); + struct croma_block *b = alloc_and_insert_block(); TAILQ_INIT(&b->args_head); expect(LPAREN); @@ -100,6 +97,7 @@ void foreach_expr(void) c++; } + free_arg(b, a); } free_block(b); @@ -138,8 +136,6 @@ void parse_arglist(struct croma_block *b) arg->value = strdup(yytext); if (arg->value == NULL) fail("Unable to allocate memory"); - - continue; break; case RPAREN: -- 2.43.0