Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : proto

Dir     : e17/proto/edje_cc


Modified Files:
        edje.l edje.y main.c 


Log Message:
- run the .edc through cpp before parsing
- pull out the # <num> <string> entries from the cpp and set the
  current file name correctly so if multiple files are included in one edc
  it will print the correct filename/line num on error
- make the formatting the same

===================================================================
RCS file: /cvsroot/enlightenment/e17/proto/edje_cc/edje.l,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- edje.l      9 Sep 2004 17:03:08 -0000       1.22
+++ edje.l      11 Sep 2004 02:37:16 -0000      1.23
@@ -7,6 +7,8 @@
     int yylex(void);
     int lnum = 1;
     int col = 0;
+    char *cur_file = NULL;
+
     static int comment = 0, cpp_comment = 0;
     static int script_level = 0;
     static char *script = NULL;
@@ -15,6 +17,7 @@
 
     #define COMMENT_END()   comment--; \
                             if (comment <= 0) { comment = 0; BEGIN(INITIAL); }
+
     #define CPP_COMMENT()   comment = 1; cpp_comment = 1;
 
     #define SCRIPT_START()  if (!comment && !cpp_comment) BEGIN(SC_SCRIPT);
@@ -193,6 +196,67 @@
 \n                  { NEW_LINE(); }
 
 \/\/                           { CPP_COMMENT(); }
+
+#[ \t]+[0-9]+[ \t]+\".*\".* {
+    /* this handles the #line <num> <name> <something>
+        * so that the linenum and cfname hold correct 
+        * values for this file
+        */              
+
+       int c;          
+       char *txt = yytext;
+       char *lpos;     
+       int count = 1;
+       char *tmp;
+       
+       c = *txt;
+
+       /* skip the # and space (until the first number) */
+       while(c == '#' || c == ' ') 
+               c = *++txt; 
+
+       lpos = txt;
+
+       /* move over all the numbers */
+       while(c >= 48 && c <= 57) {
+               c = *++txt;
+               count ++;
+       }       
+       
+       /* get the lnum from the string */
+       tmp = (char *)calloc(count + 1, sizeof(char));
+       strncpy(tmp, lpos, count);
+
+       /* subtract 1 becase gcc returns the no of the *next* line
+        * and we will add one when we hit the \n anyway */
+       lnum = atoi(tmp) - 1;
+       free(tmp);
+
+       /* now we wana get the fname so skip all space
+        * and the first " */
+       while(c == ' ' || c == '\"') 
+               c = *++txt;   
+
+       lpos = txt;
+       count = 1;
+       
+       /* move over the fname */
+       while(c != '\"') {
+               c = *++txt; 
+               count ++;
+       }
+
+       /* ignore the last " */
+       count --;
+
+       if (cur_file)
+               free(cur_file);
+
+       /* now get the fname */
+       cur_file = (char *)calloc(count + 1, sizeof(char));
+       strncpy(cur_file, lpos, count);
+}
+
 #                   { CPP_COMMENT(); }
 
 "/*"                { COMMENT_START(); }
===================================================================
RCS file: /cvsroot/enlightenment/e17/proto/edje_cc/edje.y,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- edje.y      10 Sep 2004 20:48:04 -0000      1.25
+++ edje.y      11 Sep 2004 02:37:16 -0000      1.26
@@ -8,10 +8,11 @@
        void yyerror(const char *s);
        void parse_error(void);
 
+       extern char *cur_file;
        extern int lnum;
        extern int col;
 
-        int section;
+       int section;
 
 %}
 
@@ -58,17 +59,18 @@
 
 %%
 
-edjes: /* blank */ | 
-       images edjes |
-       fonts edjes |
-       collections edjes |
-       data edjes |
-       error {
-                  parse_error();
-           yyerrok;
-           yyclearin;
-       }
-       ;
+edjes: /* blank */
+       | images edjes 
+       | fonts edjes
+       | collections edjes
+       | data edjes
+       | error {
+               parse_error();
+               yyerrok;
+               yyclearin;
+       }
+       ;
+
 collections:  COLLECTIONS {section = GROUPS; } OPEN_BRACE  collection_statement 
CLOSE_BRACE { section = BASE; }
        ;
 
@@ -76,7 +78,7 @@
        ;
 
 font_statement: /* empty */
-        | font
+       | font
        | font font_statement
        ;
 
@@ -89,7 +91,7 @@
        ;
 
 image_statement: /* empty */
-        | image
+       | image
        | image image_statement
        ;
 
@@ -112,7 +114,7 @@
        ;
 
 data_statement: /* empty */
-        | item 
+       | item 
        | item data_statement
        ;
 
@@ -135,7 +137,7 @@
        ;
 
 program_statement: /* empty */
-        | program
+       | program
        | program program_statement
        ;
 
@@ -235,7 +237,7 @@
        ;
 
 collection_statement: /* empty */
-        | group
+       | group
        | group collection_statement
        ;
 
@@ -316,7 +318,7 @@
        ;
 
 parts_statement: /* empty */
-        | part
+       | part
        | part parts_statement
        ;
 
@@ -403,7 +405,7 @@
        ;
 
 dragable_statement: /* empty */
-        | dragable_body
+       | dragable_body
        | dragable_body dragable_statement
        ;
 
@@ -518,7 +520,7 @@
        ;
 
 rel_statement: /* empty */ 
-        | rel_body
+       | rel_body
        | rel_body rel_statement
        ;
 
@@ -620,7 +622,7 @@
        ;
 
 image_statement: /* empty */ 
-        | image_body
+       | image_body
        | image_body image_statement
        ;
 
@@ -647,7 +649,7 @@
        ;
 
 fill_statement: /* empty */
-        | fill_body
+       | fill_body
        | fill_body fill_statement
        ;
 
@@ -700,7 +702,7 @@
        ;
 
 text_statement: /* empty */
-        | text_body
+       | text_body
        | text_body text_statement
        ;
 
@@ -738,26 +740,34 @@
        }
        ;
 
-exp: FLOAT                              { $$ = $1;          }
-        | exp PLUS exp                  { $$ = $1 + $3;     }
-        | exp MINUS exp                 { $$ = $1 - $3;     }
-        | exp TIMES exp                 { $$ = $1 * $3;     }
-        | exp DIVIDE exp                { $$ = $1 / $3;     }
-        | MINUS exp %prec NEG           { $$ = -$2;         }
-        | OPEN_PAREN exp CLOSE_PAREN    { $$ = $2;          }
-        ;
+exp: FLOAT                          { $$ = $1;          }
+       | exp PLUS exp                  { $$ = $1 + $3;     }
+       | exp MINUS exp                 { $$ = $1 - $3;     }
+       | exp TIMES exp                 { $$ = $1 * $3;     }
+       | exp DIVIDE exp                { $$ = $1 / $3;     }
+       | MINUS exp %prec NEG           { $$ = -$2;         }
+       | OPEN_PAREN exp CLOSE_PAREN    { $$ = $2;          }
+       ;
+
 %%
 
-void yyerror(const char *str) {
+void
+yyerror(const char *str)
+{
        fprintf(stderr, "yyerror: %s\n", str);
 }
-int yywrap() {
+
+int
+yywrap()
+{
        return 1;
 }
 
-void parse_error(void) {
+void
+parse_error(void)
+{
        fprintf(stderr, "file: %s, line: %d, column: %d\n\n",
-                                     __FILE__, lnum, col);
+                                     cur_file, lnum, col);
        exit(-1);
 }
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/proto/edje_cc/main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- main.c      9 Sep 2004 13:55:55 -0000       1.6
+++ main.c      11 Sep 2004 02:37:16 -0000      1.7
@@ -1,14 +1,23 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
 #include <getopt.h>
 #include "Etcher.h"
 
+char *filename = NULL;
+static char *work_file = NULL;
+static void clean_tmp_file(void);
+
 int main(int argc, char ** argv)
 {
-       int c;
+       int c = 0, fd = 0;
        char *file = NULL;
        extern FILE *yyin;
        extern int yydebug;
-        extern Etcher_File *etcher_file;
+       extern Etcher_File *etcher_file;
+       extern char *cur_file;
+       static char tmpn[4096];
+       char buf[4096];
 
        static struct option long_opts[] = {
                {"yydebug", no_argument, NULL, 'y'},
@@ -32,16 +41,55 @@
                printf("need input file\n");
                return 1;
        }
-       file = (char *)strdup(argv[optind]);
+       filename = (char *)strdup(argv[optind]);
+
+       strcpy(tmpn, "/tmp/etcher_cc.edc-tmp-XXXXXX");
+       fd = mkstemp(tmpn);
+       if (fd >= 0) {
+               int ret = 0;
+
+               work_file = tmpn;
+               close(fd);
+
+               atexit(clean_tmp_file);
+               snprintf(buf, sizeof(buf), "cat %s | cpp -E -o %s", filename, tmpn);
+               ret = system(buf);
+
+               if (ret < 0) {
+                       snprintf(buf, sizeof(buf), "gcc -E -o %s %s", tmpn, filename);
+                       ret = system(buf);
+               }
+
+               if (ret >= 0) 
+                       file = tmpn;
+               else {
+                       fprintf(stderr, "Unable to create temp file (%s)\n", tmpn);
+                       return 0;
+               }
+
+       } else {
+               fprintf(stderr, "Unable to create temp file (%s): %s\n", 
+                               tmpn, strerror(errno));
+               return 1;
+       }
+
        yyin = fopen(file, "r");
+       if (!yyin) {
+               fprintf(stderr, "Unable to open file (%s): %s\n", 
+                               file, strerror(errno));
+               free(file);
+               return 0;
+       }
+
        free(file);
 
-        etcher_parse_init();
+       etcher_parse_init();
 
        yyparse();
        fclose(yyin);
 
-        etcher_file_output(etcher_file, "test.out");
+       etcher_file_output(etcher_file, "test.out");
+
         /* FIXME: make this a complete test suite */
 #if 0        
         {
@@ -85,3 +133,10 @@
        return 0;
 }
 
+static void
+clean_tmp_file(void)
+{
+       if (work_file)
+               unlink(work_file);
+}
+




-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM. 
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to