-OBJS=croma.o lex.yy.o
+OBJS=croma.o lex.yy.o parse.o macro.o
CFLAGS=-c
LDFLAGS=-o croma
croma.o: croma.c
$(CC) $(CFLAGS) croma.c
+macro.o: macro.c macro.h
+ $(CC) $(CFLAGS) macro.c
+
+parse.o: parse.c parse.h
+ $(CC) $(CFLAGS) parse.c
+
lex.yy.o: lexer.l
lex lexer.l
- $(CC) $(CFLAGS) lex.yy.c
\ No newline at end of file
+ $(CC) $(CFLAGS) lex.yy.c
+
+clean:
+ rm *.o
+ rm *~
\ No newline at end of file
-#include <stdlib.h>
-
#include "parse.h"
-#include "tokens.h"
-#include "macro.h"
-
-void abort(char *msg)
+void abort(char *fmt, ...)
{
- fprintf(stderr, "%s\n");
+ va_list ap;
+ va_start(ap, fmt);
+
+ fprintf(stderr, fmt, ap);
+
+ va_end(ap);
+
exit(EXIT_FAILURE);
}
case FOREACH:
foreach_expr();
break;
+
+ default:
+ abort("garbage somewhere in input");
}
}
parse_arglist(b);
expect(LBRACKET);
+
+ parse_block(b);
+
+ char *p = b->parameters;
+ char *t = b->contents;
+ if (t == NULL)
+ abort("the impossible happened : b->contents == NULL !, file: %s, line %d", __FILE__, __LINE__);
+
+ while(strcmp(p, "\0") != 0) {
+ while(t != '\0') {
+ if (*t == '$' && *t+1 == '$') {
+ printf("%s", p);
+ t++; /* skip them second '$' */
+ } else {
+ printf("%c", *t);
+ }
+
+ t++;
+ }
+ p++;
+ }
}
void parse_arglist(struct croma_block *b)
{
if (b == NULL)
- abort("the impossible happened : b == NULL !");
+ abort("the impossible happened : b == NULL !, file: %s, line %d", __FILE__, __LINE__);
b->parameters = malloc(16*sizeof(char *));
int i;
expect(RPAREN);
}
+
+void parse_block(struct croma_block *b)
+{
+ 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__);
+
+ /* 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);
+ yylex();
+ }
+
+ return;
+
+}
#ifndef __CROMA_PARSE_H__
#define __CROMA_PARSE_H__
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "tokens.h"
+#include "macro.h"
+
#define MAX_PARAM_LEN 4096
-void abort(char *msg);
+void abort(char *fmt, ...);
void init_parser(void);
void yyparse(void);
void foreach_expr(void);
void parse_arglist(struct croma_block *b);
+void parse_block(struct croma_block *b);
#endif
#define __TOKENS_H__
enum {
- LPAREN, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, FOREACH,
+ LPAREN, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, COMMA, FOREACH,
};
char *token_list[] = { "left parenthesis",
"word",
"$$ sign",
"spaces",
+ "comma",
"foreach", };
extern int yylex(void);
+extern char *yytext;
#endif