Enlightenment CVS committal

Author  : tsauerbeck
Project : e17
Module  : libs/edje

Dir     : e17/libs/edje/src/bin


Modified Files:
        edje_cc_parse.c 


Log Message:
edje_cc now knows about parens, which means that "(x + y + z)" is treated as 
*one* token.
this made it possible to fix edje_cc's math code a bit.
NOTE: only fixed point arithmetic works again, floating point stuff doesn't!
See the FIXME for ideas on how to handle this.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/edje/src/bin/edje_cc_parse.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -3 -r1.31 -r1.32
--- edje_cc_parse.c     9 Nov 2004 09:31:08 -0000       1.31
+++ edje_cc_parse.c     15 Dec 2004 17:58:10 -0000      1.32
@@ -6,6 +6,8 @@
 
 static void  new_object(void);
 static void  new_statement(void);
+static char *perform_math (char *input);
+static void  preprocess_params (void);
 static int   isdelim(char c);
 static char *next_token(char *p, char *end, char **new_p, int *delim);
 static char *stack_id(void);
@@ -118,6 +120,50 @@
    free(id);
 }
 
+static void
+preprocess_params (void)
+{
+   Evas_List *l;
+
+   /* a formula will never be spread across multiple params */
+   for (l = params; l; l = l->next) {
+       char *data = l->data;
+       char *replace = NULL;
+
+       /* if the token begins with a opening parens, the user wants us
+        * to do some math :)
+        */
+       if (*data == '(')
+         {
+            replace = perform_math (data);
+
+            free (l->data);
+            l->data = replace;
+         }
+
+   }
+}
+
+static char *
+perform_math (char *input)
+{
+   char buf[256];
+   int res;
+
+   /* FIXME
+    * This is a bad hack, we're just assuming that the user wants to
+    * use fixed point arithmetic here :O
+    *
+    * What we should do is, loop over the string and figure out whether
+    * there are floating point operands, too and then switch to
+    * floating point math.
+    */
+   res = my_atoi (input);
+   snprintf (buf, sizeof (buf), "%i", res);
+
+   return strdup (buf);
+}
+
 static int
 isdelim(char c)
 {
@@ -139,6 +185,7 @@
    char *tok_start = NULL, *tok_end = NULL, *tok = NULL, *sa_start = NULL;
    int in_tok = 0;
    int in_quote = 0;
+   int in_parens = 0;
    int in_comment_ss  = 0;
    int in_comment_cpp = 0;
    int in_comment_sa  = 0;
@@ -220,6 +267,9 @@
                                 in_quote = 1;
                                 had_quote = 1;
                              }
+                           else if (*p == '(')
+                             in_parens++;
+
                            in_tok = 1;
                            tok_start = p;
                            if (isdelim(*p)) *delim = 1;
@@ -236,6 +286,11 @@
                            had_quote = 1;
                         }
                    }
+                 else if (in_parens)
+                   {
+                      if (((*p) == ')') && (*(p - 1) != '\\'))
+                        in_parens--;
+                   }
                  else
                    {
                       if (*p == '"')
@@ -243,6 +298,10 @@
                            in_quote = 1;
                            had_quote = 1;
                         }
+                      else if (*p == '(')
+                        in_parens++;
+
+                      /* check for end-of-token */
                       if (
                           (isspace(*p)) ||
                           ((*delim) && (!isdelim(*p))) ||
@@ -378,6 +437,7 @@
                  if (do_params)
                    {
                       do_params = 0;
+                      preprocess_params ();
                       new_statement();
                       /* clear out params */
                       while (params)




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to