Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/edje

Dir     : e17/libs/edje/src/bin


Modified Files:
        edje_cc_parse.c 


Log Message:


edje_cc now supports cpp, if you have it installed, so you can #include,
#define etc. now in your .edc files.... much friendlier :)

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/edje/src/bin/edje_cc_parse.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- edje_cc_parse.c     30 Jul 2003 02:58:22 -0000      1.10
+++ edje_cc_parse.c     29 Aug 2003 08:34:53 -0000      1.11
@@ -12,6 +12,8 @@
 Evas_List *stack = NULL;
 Evas_List *params = NULL;
 
+static char file_buf[4096];
+
 static void
 new_object(void)
 {
@@ -91,9 +93,12 @@
    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 @@
        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 @@
             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
+             * # <line no. of next line> <filename from next line on> [??]
+             */
+            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 @@
      }
 }
 
+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)
      {




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to