Hey,

The edje bug I was hunting on the windows platform comes from eet. the %a modifier, used to get the float or double values, is not supported on windows (see the big comment in the patch).

I have some questions about that patch:

1) do I copy/paste it for float or do I factorize the code ? (only the last lines are specific to double).

2) Does someone see improvements regards the speed or the algorithm ?

3) I see a comment about solaris in the eet_data_get_double() function. Should we use that function on the solaris platform ? If so, which preprocessor command I have to use ?

thank you

Vincent Torri
? eet_win32.patch
Index: eet_data.c
===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/eet_data.c,v
retrieving revision 1.46
diff -u -r1.46 eet_data.c
--- eet_data.c  28 Dec 2006 15:23:47 -0000      1.46
+++ eet_data.c  28 Aug 2007 13:36:50 -0000
@@ -125,6 +125,8 @@
 
 /*---*/
 
+static double eet_data_string_double_convert(const char *src);
+
 static int   eet_data_get_char(void *src, void *src_end, void *dest);
 static void *eet_data_put_char(const void *src, int *size_ret);
 static int   eet_data_get_short(void *src, void *src_end, void *dest);
@@ -201,6 +203,103 @@
 
 /*---*/
 
+/* On windows (using MinGW or VC++), printf-like functions */
+/* use the MSVCRT library, which does not support fully    */
+/* the C99 spec. Hence they do not support the modifier    */
+/* character %a.                                           */
+/*                                                         */
+/* That function converts a string created by a valid %a   */
+/* modifer to a double.                                    */
+/*                                                         */
+/* The string must have the following format:              */
+/*                                                         */
+/*  [-]0xh.hhhhhp[+-]e                                     */
+/*                                                         */
+/* where e is a decimal number.                            */
+/* If n is the number of cyphers after the point, the      */
+/* computed value is:                                      */
+/*                                                         */
+/*  [-]hhhhhh * (2^[+-]e) / (16^n)                         */
+/*                                                         */
+/* That code is as simple and readable as possible. So it  */
+/* can be improved.                                        */
+static double
+eet_data_string_double_convert(const char *src)
+{
+  const char *str;
+  double      val;
+  long long   mantisse;
+  int         nbr_decimals;
+  int         exponent;
+  char        sign;
+
+  str = src;
+  mantisse = +1;
+
+  if (*str == '-')
+    {
+       mantisse = -1;
+       str++;
+    }
+  else if (*str == '0')
+    {
+       str++;
+       if (*str == 'x')
+         {
+            str++;
+            goto compute_mantisse;
+        }
+       else
+         {
+            fprintf(stderr, "Error during conversion");
+            return 0.0;
+         }
+    }
+  else
+    {
+      fprintf(stderr, "Error during conversion");
+      return 0.0;
+    }
+
+ compute_mantisse:
+  nbr_decimals = 0;
+  mantisse *= (*str >= 'a') ? *str - 'a'  + 10 : *str - '0';
+  str++;
+  if (*str == '.')
+    {
+      str++;
+      while (*str != 'p')
+        {
+          mantisse = (mantisse << 4);
+          mantisse += (*str >= 'a') ? *str - 'a'  + 10 : *str - '0';
+          str++;
+          nbr_decimals++;
+        }
+    }
+  if (*str != 'p')
+    {
+      fprintf(stderr, "Error during conversion");
+      return 0.0;
+    }
+  sign = +1;
+  str++;
+  if (*str == '-')
+    {
+       sign = -1;
+       str++;
+    }
+  else if (*str == '+') str++;
+  sscanf (str, "%d", &exponent);
+
+  val = (double)mantisse / (double)(1 << (nbr_decimals << 2));
+  if (sign > 0)
+    val *= (double)(1 << exponent);
+  else
+    val /= (double)(1 << exponent);
+
+  return (double)val;
+}
+
 /* CHAR TYPE */
 static int
 eet_data_get_char(void *src, void *src_end, void *dst)
@@ -413,16 +512,20 @@
    p = s;
    len = 0;
    while ((p < (char *)src_end) && (*p != 0)) {len++; p++;}
+#ifdef _WIN32
+   *d = eet_data_string_double_convert(s);
+#else
    str = alloca(len + 1);
    memcpy(str, s, len);
    str[len] = 0;
 
    prev_locale = setlocale(LC_NUMERIC, "C");
-/* solaris atof is broken and doesnt understand %a format as a float */   
+/* solaris atof is broken and doesnt understand %a format as a float */
 /*   *d = (double)atof(str); */
    sscanf(str, "%a", &tf);
    *d = (double)tf;
    if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
+#endif
 
    return len + 1;
 }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to