From: khamidou Date: Sun, 1 Mar 2009 15:37:54 +0000 (+0100) Subject: added a few fixes here and there X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=d87a77d9379eff43dc06e4c98b4fc08b53e6ebb6;p=croma.git added a few fixes here and there --- diff --git a/lexer.l b/lexer.l index 22d6669..f0279b9 100644 --- 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 1c159c2..339313d 100644 --- 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 13a776e..da43ff9 100644 --- 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;