+#include <string.h>
#include "parse.h"
-void abort(char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
-
- fprintf(stderr, fmt, ap);
+extern char *strndup (__const char *__string, size_t __n);
+extern char *yytext;
- va_end(ap);
+char *token_list[] = { "left parenthesis",
+ "right parenthesis",
+ "{{",
+ "}}",
+ "word",
+ "$$ sign",
+ "spaces",
+ "comma",
+ "foreach", NULL};
- exit(EXIT_FAILURE);
-}
void expect(int t)
{
int c = yylex();
if (c != t) {
- fprintf(stderr, "Expected token %s in input, got %s (%s).\n", token_list[t], token_list[c], yytext);
- exit(EXIT_FAILURE);
+ fail("Expected token %s in input, got %s (%s).\n",
+ token_list[t], token_list[c], yytext);
+ fail("unexpected token : %s \n", yytext);
}
}
break;
default:
- abort("garbage somewhere in input");
+ fail("garbage somewhere in input.\n");
}
}
{
struct croma_block *b = alloc_and_insert_block();
- int t = yylex();
-
expect(LPAREN);
parse_arglist(b);
parse_block(b);
- char *p = b->parameters;
+ char **p = b->parameters;
char *c = b->contents;
if (c == NULL)
- abort("the impossible happened : b->contents == NULL !, file: %s, line %d", __FILE__, __LINE__);
+ fail("the impossible happened : b->contents == NULL !, file: %s, line %d", __FILE__, __LINE__);
- while(strcmp(p, "\0") != 0) {
+ while(strcmp(*p, "\0") != 0) {
while(c != '\0') {
if (*c == '$' && *c+1 == '$') {
printf("%s", p);
void parse_arglist(struct croma_block *b)
{
if (b == NULL)
- abort("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
+ fail("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
b->parameters = malloc(16*sizeof(char *));
- char *s = b->parameters;
+ char **p = b->parameters;
int i;
- int t = yylex();
expect(WORD);
*/
for (i = 0; i < 16; i++)
{
- *s++ = strndup(yytext, MAX_PARAM_LEN);
+ *p++ = strndup(yytext, MAX_PARAM_LEN);
expect(COMMA);
expect(WORD);
}
- *s++ = "\0";
+ *p++ = "\0";
expect(RPAREN);
int i = 0; /* FIXME : realloc() b->contents on the fly*/
if (b == NULL)
- abort("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
+ fail("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
/* Copy the whole buffer in b->contents.
FIXME: expand macros before copying contents.
int t = yylex();
while (t != RBRACKET && i < 8192) {
- i += strncat(b->contents, yytext, 8192 - i);
+ strncat(b->contents, yytext, 8192 - i);
+ i += strlen(yytext);
yylex();
}
#define __TOKENS_H__
enum {
- LPAREN, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, COMMA,
+ LPAREN = 0, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, COMMA,
FOREACH,
};
-char *token_list[] = { "left parenthesis",
- "right parenthesis",
- "{{",
- "}}",
- "word",
- "$$ sign",
- "spaces",
- "comma",
- "foreach", };
extern int yylex(void);
extern char *yytext;