]> khamidou — GitHub mirrors - croma.git/commitdiff
implemented foreach() at last
authorkhamidou <karim@lambda-expr.org>
Mon, 2 Mar 2009 17:51:12 +0000 (18:51 +0100)
committerkhamidou <karim@lambda-expr.org>
Mon, 2 Mar 2009 17:51:12 +0000 (18:51 +0100)
macro.c
macro.h
parse.c

diff --git a/macro.c b/macro.c
index 41c60edef9e86e1baf00d7f066e66645102c58cc..9786d46bab814cd41b80386e69215c84e6041af6 100644 (file)
--- 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 d9f904b13b9395cec7a45bf1a13c9c11e3756108..1a1a8270e3c902b8fa0493799a62ba4e711bef8f 100644 (file)
--- 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 0163b7aa2cd85df26a6fb94675ff6aeab62addf9..89a38359457da9c14fda4366086671ac2c11a8e7 100644 (file)
--- 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: