]> khamidou — GitHub mirrors - croma.git/commitdiff
added a few fixes here and there
authorkhamidou <karim@lambda-expr.org>
Sun, 1 Mar 2009 15:37:54 +0000 (16:37 +0100)
committerkhamidou <karim@lambda-expr.org>
Sun, 1 Mar 2009 15:37:54 +0000 (16:37 +0100)
lexer.l
macro.h
parse.c

diff --git a/lexer.l b/lexer.l
index 22d6669a0b516f19be99fea669936fa22a4f7cdb..f0279b913f51d6697a7ebef21140b5737de54fdb 100644 (file)
--- a/lexer.l
+++ b/lexer.l
@@ -16,7 +16,7 @@ int yywrap()
 
 %%
 
-"("            { return LPAREN;        }
+"("            { return LPAREN;        }
 ")"            { return RPAREN;        }
 "{{"           { return LBRACKET;      }
 "}}"           { return RBRACKET;      }
diff --git a/macro.h b/macro.h
index 1c159c20f921a0951108d61dc3e84782cfe912d2..339313d0cb1a02cd68f8d15db00e60dec5021226 100644 (file)
--- a/macro.h
+++ b/macro.h
@@ -14,7 +14,8 @@
 
 struct croma_block {
        char *name;
-       char **parameters;
+//     char **parameters;
+       char *parameters[16];
        char *contents;
        TAILQ_ENTRY(croma_block) blocks;
 };
diff --git a/parse.c b/parse.c
index 13a776ea162ff728eaf2e2c2e4ed366dae506e87..da43ff9680135ddb742d3b5b5d184988676dbaaf 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -86,8 +86,12 @@ void parse_arglist(struct croma_block *b)
        if (b == NULL)
                fail("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
 
-       b->parameters = malloc(16*sizeof(char *));
-       char **p = b->parameters;
+//     b->parameters = malloc(16*sizeof(char *));
+
+/*     if (b->parameters == NULL)
+               fail("Unable to allocate enough memory !");
+*/
+//     char **p = b->parameters;
 
        int i;
 
@@ -98,12 +102,24 @@ void parse_arglist(struct croma_block *b)
        */
        for (i = 0; i < 16; i++)
        {
-               *p++ = strndup(yytext, MAX_PARAM_LEN);
-               expect(COMMA);
+               b->parameters[i] = strdup(yytext);
+               if (b->parameters[i] == NULL)
+                       fail("Unable to alloc memory for text %s\n", yytext);
+
+               int c = yylex();
+               if (c == RPAREN)
+                       return;
+               else if (c != COMMA) {
+                       puts("Expected a comma in parameter list");
+                       exit(-1);
+               }
+
                expect(WORD);
+
+               
        }
 
-       *p++ = "\0";
+//     *p++ = "\0";
 
        expect(RPAREN);
 
@@ -116,6 +132,11 @@ void parse_block(struct croma_block *b)
        if (b == NULL) 
                fail("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
 
+       b->contents = malloc(8192);
+
+       if (b->contents == NULL)
+               fail("Unable to alloc memory for input buffer", __FILE__, __LINE__);
+
        /* Copy the whole buffer in b->contents.
           FIXME: expand macros before copying contents.
         */
@@ -124,7 +145,7 @@ void parse_block(struct croma_block *b)
        while (t != RBRACKET && i < 8192) {
                strncat(b->contents, yytext, 8192 - i);
                i += strlen(yytext);
-               yylex();
+               t = yylex();
        }
 
        return;