From b3c6f96f24d210272535db9754b489a3ba564588 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Fri, 29 Aug 2003 08:34:53 +0000 Subject: [PATCH] edje_cc now supports cpp, if you have it installed, so you can #include, #define etc. now in your .edc files.... much friendlier :) SVN revision: 7390 --- legacy/edje/src/bin/edje_cc_parse.c | 80 +++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/legacy/edje/src/bin/edje_cc_parse.c b/legacy/edje/src/bin/edje_cc_parse.c index 28a18877c5..616feab494 100644 --- a/legacy/edje/src/bin/edje_cc_parse.c +++ b/legacy/edje/src/bin/edje_cc_parse.c @@ -12,6 +12,8 @@ int line = 0; Evas_List *stack = NULL; Evas_List *params = NULL; +static char file_buf[4096]; + static void new_object(void) { @@ -91,9 +93,12 @@ next_token(char *p, char *end, char **new_p, int *delim) char *tok_start = NULL, *tok_end = NULL, *tok = NULL, *sa_start = NULL; int in_tok = 0; int in_quote = 0; - int in_comment_ss = 0; - int in_comment_sa = 0; + int in_comment_ss = 0; + int in_comment_cpp = 0; + int in_comment_sa = 0; int had_quote = 0; + char *cpp_token_line = NULL; + char *cpp_token_file = NULL; *delim = 0; if (p >= end) return NULL; @@ -102,6 +107,9 @@ next_token(char *p, char *end, char **new_p, int *delim) if (*p == '\n') { in_comment_ss = 0; + in_comment_cpp = 0; + cpp_token_line = NULL; + cpp_token_file = NULL; line++; } if ((!in_comment_ss) && (!in_comment_sa)) @@ -109,14 +117,51 @@ next_token(char *p, char *end, char **new_p, int *delim) if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '/')) in_comment_ss = 1; if ((!in_quote) && (*p == '#')) - in_comment_ss = 1; + in_comment_cpp = 1; if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '*')) { in_comment_sa = 1; sa_start = p; } } - if ((!in_comment_ss) && (!in_comment_sa)) + if ((in_comment_cpp) && (*p == '#')) + { + char *pp, fl[4096]; + char *tmpstr = NULL; + int l, nm; + + /* handle cpp comments */ + /* their line format is + * # [??] + */ + cpp_token_line = NULL; + cpp_token_file = NULL; + + pp = p; + while ((pp < end) && (*pp != '\n')) + { + pp++; + } + l = pp - p; + tmpstr = malloc(l + 1); + if (!tmpstr) + { + fprintf(stderr, "%s: Error. %s:%i malloc %i bytes failed\n", + progname, file_in, line, l + 1); + exit(-1); + } + strncpy(tmpstr, p, l); + tmpstr[l] = 0; + l = sscanf(tmpstr, "%*s %i \"%[^\"]\"", &nm, fl); + if (l == 2) + { + strcpy(file_buf, fl); + line = nm; + file_in = file_buf; + } + free(tmpstr); + } + else if ((!in_comment_ss) && (!in_comment_sa) && (!in_comment_cpp)) { if (!in_tok) { @@ -318,13 +363,40 @@ parse(char *data, off_t size) } } +static char *clean_file = NULL; +static void +clean_tmp_file(void) +{ + if (clean_file) unlink(clean_file); +} + void compile(void) { int fd; off_t size; char *data; + char buf[4096]; + static char tmpn[4096]; + strcpy(tmpn, "/tmp/edje_cc.edc-tmp-XXXXXX"); + fd = mkstemp(tmpn); + if (fd >= 0) + { + int ret; + + clean_file = tmpn; + close(fd); + atexit(clean_tmp_file); + snprintf(buf, sizeof(buf), "cpp %s -o %s", file_in, tmpn); + ret = system(buf); + if (ret < 0) + { + snprintf(buf, sizeof(buf), "gcc -E %s -o %s", file_in, tmpn); + ret = system(buf); + } + if (ret >= 0) file_in = tmpn; + } fd = open(file_in, O_RDONLY); if (fd < 0) {