Enlightenment CVS committal

Author  : handyande
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_config


Modified Files:
        Ecore_Config.h ecore_config.c ecore_config_db.c 
        ecore_config_extra.c 


Log Message:
Morten Nilsen's latest patches for ecore_config argb etc
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/Ecore_Config.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -3 -r1.47 -r1.48
--- Ecore_Config.h      27 Dec 2005 17:17:30 -0000      1.47
+++ Ecore_Config.h      8 Jan 2006 14:57:14 -0000       1.48
@@ -137,14 +137,10 @@
    EAPI Ecore_Config_Prop  *ecore_config_get(const char *key);
    EAPI const char         *ecore_config_type_get(const Ecore_Config_Prop *e);
    EAPI int                 ecore_config_boolean_get(const char *key);
-   EAPI void               *ecore_config_data_get(const char *key);
    EAPI char               *ecore_config_string_get(const char *key);
    EAPI long                ecore_config_int_get(const char *key);
-   EAPI int                 ecore_config_rgb_get(const char *key, int *r, int 
*g,
-                                                int *b);
    EAPI int                 ecore_config_argb_get(const char *key, int *a, int 
*r,
                                                  int *g, int *b);
-   EAPI char               *ecore_config_rgbstr_get(const char *key);
    EAPI char               *ecore_config_argbstr_get(const char *key);
    EAPI float               ecore_config_float_get(const char *key);
    EAPI char               *ecore_config_theme_get(const char *key);
@@ -161,9 +157,8 @@
    EAPI int                 ecore_config_boolean_set(const char *key, int val);
    EAPI int                 ecore_config_string_set(const char *key, char 
*val);
    EAPI int                 ecore_config_int_set(const char *key, int val);
-   EAPI char               *ecore_config_rgb_to_argb(char *rgb);
-   EAPI int                 ecore_config_rgb_set(const char *key, char *val);
-   EAPI int                 ecore_config_argb_set(const char *key, char *val);
+   EAPI int                 ecore_config_argb_set(const char *key, int a, int 
r, int g, int b);
+   EAPI int                 ecore_config_argbstr_set(const char *key, char 
*val);
    EAPI int                 ecore_config_float_set(const char *key, float val);
    EAPI int                 ecore_config_theme_set(const char *key, char *val);
    EAPI int                 ecore_config_theme_preview_group_set(const char 
*key,
@@ -183,8 +178,8 @@
    EAPI int                 ecore_config_float_default_bound(const char *key,
                                                             float val, float 
lo,
                                                             float hi, float 
step);
-   EAPI int                 ecore_config_rgb_default(const char *key, char 
*val);
-   EAPI int                 ecore_config_argb_default(const char *keym, char 
*val);
+   EAPI int                 ecore_config_argb_default(const char *key, int a, 
int r, int g, int b);
+   EAPI int                 ecore_config_argbstr_default(const char *key, char 
*val);
    EAPI int                 ecore_config_theme_default(const char *key, char 
*val);
 
    EAPI int                 ecore_config_listen(const char *name, const char 
*key,
@@ -290,9 +285,6 @@
                                                            char short_opt,
                                                            char *long_opt,
                                                            char *desc);
-   EAPI int                 ecore_config_rgb_create(const char *key, char *val,
-                                                   char short_opt, char 
*long_opt,
-                                                   char *desc);
    EAPI int                 ecore_config_argb_create(const char *key, char 
*val,
                                                     char short_opt, char 
*long_opt,
                                                     char *desc);
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -3 -r1.70 -r1.71
--- ecore_config.c      6 Jan 2006 18:26:36 -0000       1.70
+++ ecore_config.c      8 Jan 2006 14:57:14 -0000       1.71
@@ -27,6 +27,9 @@
 static int           _ecore_config_system_init_no_load(void);
 static int           _ecore_config_system_load(void);
 
+static inline void  *__ecore_argb_to_long(int a, int r, int g, int b, long *v);
+static inline void  *__ecore_argbstr_to_long(char *argb, long *v);
+
 static const char  *_ecore_config_type[] =
    { "undefined", "integer", "float", "string", "colour", "theme", "boolean" };
 
@@ -140,22 +143,6 @@
 }
 
 /**
- * Obtains the data pointed to by the specified property.
- * @param   key The property key.
- * @return  Data pointer used by the property.
- * @ingroup Ecore_Config_Get_Group
- */
-EAPI void               *
-ecore_config_data_get(const char *key)
-{
-   Ecore_Config_Prop  *e;
-
-   e = ecore_config_get(key);
-   return (e ? ((e->type == ECORE_CONFIG_STR) ? ((void *)&e->ptr) : ((void 
*)&e->val))
-          : NULL);
-}
-
-/**
  * Returns the specified property as a string.
  * @param   key The property key.
  * @return  The string value of the property.  The function returns @c NULL if
@@ -232,23 +219,6 @@
 }
 
 /**
- * Finds the red, green and blue values of a color property.
- * @param   key The property key.
- * @param   r   A pointer to an integer to store the red value into.
- * @param   g   A pointer to an integer to store the green value into.
- * @param   b   A pointer to an integer to store the blue value into.
- * @return  @c ECORE_CONFIG_ERR_SUCC on success.  @c ECORE_CONFIG_ERR_FAIL
- *          otherwise.
- * @ingroup Ecore_Config_Get_Group
- * @deprecated
- */
-EAPI int
-ecore_config_rgb_get(const char *key, int *r, int *g, int *b)
-{
-   return _ecore_config_argb_get( ecore_config_get(key), NULL, r, g, b);
-}
-
-/**
  * Finds the alpha, red, green and blue values of a color property.
  * @param   key The property key.
  * @param   a   A pointer to an integer to store the alpha value into.
@@ -272,8 +242,8 @@
      {
        if(a) *a = (e->val >> 24) & 0xff;
        if(r) *r = (e->val >> 16) & 0xff;
-       if(g) *g = (e->val >> 8) & 0xff;
-       if(b) *b = e->val & 0xff;
+       if(g) *g = (e->val >>  8) & 0xff;
+       if(b) *b =  e->val        & 0xff;
        return ECORE_CONFIG_ERR_SUCC;
      }
    return ECORE_CONFIG_ERR_FAIL;
@@ -282,24 +252,6 @@
 /**
  * Returns a color property as a string of hexadecimal characters.
  * @param   key The property key.
- * @return  A string of hexadecimal characters in the format #rrggbb.
- * @ingroup Ecore_Config_Get_Group
- * @deprecated
- */
-EAPI char               *
-ecore_config_rgbstr_get(const char *key)
-{
-   char               *argb, *rgb;
-
-   argb = ecore_config_argbstr_get(key);
-   rgb = argb + 2;
-   *rgb = '#';
-   return rgb;
-}
-
-/**
- * Returns a color property as a string of hexadecimal characters.
- * @param   key The property key.
  * @return  A string of hexadecimal characters in the format #aarrggbb.
  * @ingroup Ecore_Config_Get_Group
  */
@@ -492,79 +444,44 @@
 static int
 ecore_config_typed_val(Ecore_Config_Prop * e, const void *val, int type)
 {
-   char               *l;
-   long                v;
-   int                *i;
-   float              *f;
 
-   l = NULL;
-   v = 0;
+   if (!e)
+     return ECORE_CONFIG_ERR_NODATA;
 
-   if (!(val))
+   if (!(val) && type != ECORE_CONFIG_NIL)
       e->ptr = NULL;
    else
      {
-       if (type == ECORE_CONFIG_INT)
-         {
-            i = (int *)val;
-            e->val = (long)*i;
-            e->type = ECORE_CONFIG_INT;
-         }
-       else if (type == ECORE_CONFIG_BLN )
-         {
-            i = (int *)val;
-            e->val = (long)*i;
-            e->type = ECORE_CONFIG_BLN;
-         }
+       if (type == ECORE_CONFIG_INT || type == ECORE_CONFIG_BLN)
+          {
+            e->val = (long) *((int *)val);
+            e->type = type;
+          }
        else if (type == ECORE_CONFIG_STR || type == ECORE_CONFIG_THM)
-         {
+          {
             if (!(e->ptr = strdup(val)))
                return ECORE_CONFIG_ERR_OOM;
             if (e->type == ECORE_CONFIG_NIL)
                e->type = type;
-         }
+          }
        else if (type == ECORE_CONFIG_RGB)
-         {
-            if (((char *)val)[0] == '#')
-              {
-                 if ((v = (long) strtoul(&((char *)val)[1], &l, 16)) < 0)
-                   {
-                      v = 0;
-                      E(0,
-                        "ecore_config_val: key \"%s\" -- hexadecimal value 
less than zero, bound to zero...\n",
-                        (char *)val);
-                      l = (char *)val;
-                   }
-              }
-            else
-              {
-                 E(0,
-                   "ecore_config_val: key \"%s\" -- value \"%s\" not a valid 
hexadecimal RGB value?\n",
-                   e->key, (char *)val);
-                 return ECORE_CONFIG_ERR_FAIL;
-              }
-            if (*l)
-               E(0,
-                 "ecore_config_val: key \"%s\" -- value \"%s\" not a valid 
hexadecimal RGB value?\n",
-                 e->key, (char *)val);
-            else
-              {
-                 e->val = v;
-                 e->type = ECORE_CONFIG_RGB;
-              }
+          {
+            e->val = *((long *)val);
+            e->type = ECORE_CONFIG_RGB;
          }
        else if (type == ECORE_CONFIG_FLT)
          {
-            f = (float *)val;
-            e->val = (long)((*f) * ECORE_CONFIG_FLOAT_PRECISION);
+            e->val = (long) ((*((float *)val)) * ECORE_CONFIG_FLOAT_PRECISION);
             e->type = ECORE_CONFIG_FLT;
          }
        else
+{
           e->type = ECORE_CONFIG_NIL;
+}
 
        ecore_config_bound(e);
        e->flags |= ECORE_CONFIG_FLAG_MODIFIED;
-  e->flags = e->flags & ~ECORE_CONFIG_FLAG_CMDLN;
+       e->flags &= ~ECORE_CONFIG_FLAG_CMDLN;
        return ECORE_CONFIG_ERR_SUCC;
      }
    return ECORE_CONFIG_ERR_IGNORED;
@@ -574,40 +491,39 @@
 ecore_config_typed_add(const char *key, const void *val, int type)
 {
    int error = ECORE_CONFIG_ERR_SUCC;
-   Ecore_Config_Prop  *e;
+   Ecore_Config_Prop  *e = NULL;
    Ecore_Config_Bundle *t;
 
    t = __ecore_config_bundle_local;
    if (!key)
       return ECORE_CONFIG_ERR_NODATA;
 
-   if (!(e = malloc(sizeof(Ecore_Config_Prop))))
-      goto ret;
-   memset(e, 0, sizeof(Ecore_Config_Prop));
-
-   if (!(e->key = strdup(key)))
+   if (!(e = calloc(1, sizeof(Ecore_Config_Prop))))
      {
        error = ECORE_CONFIG_ERR_OOM;
-        goto ret_free_nte;
      }
-
-   if ((error = ecore_config_typed_val(e, val, type) != ECORE_CONFIG_ERR_SUCC))
-      goto ret_free_key;
-
-   e->next = t ? t->data : NULL;
-   if (t)
+   else if (!(e->key = strdup(key)))
+     {
+       error = ECORE_CONFIG_ERR_OOM;
+     }
+   else if ((error = ecore_config_typed_val(e, val, type)) == 
ECORE_CONFIG_ERR_SUCC)
      {
-       t->data = e;
+       if (t)
+          {
+            e->next = t->data;
+            t->data = e;
+          }
        return ECORE_CONFIG_ERR_SUCC;
      }
 
- ret_free_key:
-   free(e->key);
- ret_free_nte:
-   free(e);
- ret:
+   if(e->key)
+     free(e->key);
+   if(e)
+     free(e);
+
    if (error == ECORE_CONFIG_ERR_SUCC)
       error = ECORE_CONFIG_ERR_FAIL;
+
    return error;
 }
 
@@ -826,35 +742,23 @@
    return ecore_config_typed_set(key, (void *)&val, ECORE_CONFIG_FLT);
 }
 
-EAPI char              *
-ecore_config_rgb_to_argb(char *rgb)
-{
-   char               *argb;
-
-   argb = malloc(strlen(rgb) + 2);
-   strncpy(argb, "#ff", 3);
-   strncat(argb, rgb+1, strlen(rgb - 1));
-   return argb;
-}
-
 /**
  * Sets the indicated property to a color value.
  * @param   key The property key
- * @param   val Color value in RGB format.
+ * @param   a integer 0..255
+ * @param   r integer 0..255
+ * @param   g integer 0..255
+ * @param   b integer 0..255
+ *   
  * @return  @c ECORE_CONFIG_ERR_SUCC if the property is set successfully.
  * @ingroup Ecore_Config_Set_Group
  * @deprecated
  */
 EAPI int
-ecore_config_rgb_set(const char *key, char *val)
+ecore_config_argb_set(const char *key, int a, int r, int g, int b)
 {
-   char               *argb;
-   int                 ret;
-
-   argb = ecore_config_rgb_to_argb(val);
-   ret = ecore_config_argb_set(key, argb);
-   free(argb);
-   return ret;
+   long v = 0;
+   return ecore_config_typed_set(key, __ecore_argb_to_long(a,r,g,b, &v), 
ECORE_CONFIG_RGB);
 }
 
 /**
@@ -865,9 +769,10 @@
  * @ingroup Ecore_Config_Set_Group
  */
 EAPI int
-ecore_config_argb_set(const char *key, char *val)
+ecore_config_argbstr_set(const char *key, char *val)
 {
-   return ecore_config_typed_set(key, (void *)val, ECORE_CONFIG_RGB);
+   long v = 0;
+   return ecore_config_typed_set(key, __ecore_argbstr_to_long(val, &v), 
ECORE_CONFIG_RGB);
 }
 
 /**
@@ -1118,21 +1023,19 @@
  * Sets the indicated property to a color value if the property has not yet
  * been set.
  * @param  key The property key.
- * @param  val Color value in RGB format.
+ * @param  a integer 0..255
+ * @param  r integer 0..255
+ * @param  g integer 0..255
+ * @param  b integer 0..255
  * @return @c ECORE_CONFIG_ERR_SUCC if there are no problems.
  * @ingroup Ecore_Config_Default_Group
  * @deprecated
  */
 EAPI int
-ecore_config_rgb_default(const char *key, char *val)
+ecore_config_argb_default(const char *key, int a, int r, int g, int b)
 {
-   char               *argb;
-   int                 ret;
-
-   argb = ecore_config_rgb_to_argb(val);
-   ret = ecore_config_argb_default(key, argb);
-   free(argb);
-   return ret;
+   long v = 0;
+   return ecore_config_typed_default(key, __ecore_argb_to_long(a,r,g,b, &v), 
ECORE_CONFIG_RGB);
 }
 
 /**
@@ -1144,9 +1047,10 @@
  * @ingroup Ecore_Config_Default_Group
  */
 EAPI int
-ecore_config_argb_default(const char *key, char *val)
+ecore_config_argbstr_default(const char *key, char *val)
 {
-   return ecore_config_typed_default(key, (void *)val, ECORE_CONFIG_RGB);
+   long v = 0;
+   return ecore_config_typed_default(key, __ecore_argbstr_to_long(val, &v), 
ECORE_CONFIG_RGB);
 }
 
 /**
@@ -1486,7 +1390,6 @@
 {
    char                *path;
    Ecore_Config_Prop   *list;
-   Ecore_Config_Bundle *temp;
    _ecore_config_system_init_no_load();
 
    __ecore_config_app_name = strdup(name);
@@ -1494,12 +1397,11 @@
    if (!__ecore_config_server_local)
       return ECORE_CONFIG_ERR_FAIL;
 
-   temp = __ecore_config_bundle_local;
    list = __ecore_config_bundle_local->data;
+   free( __ecore_config_bundle_local );
    __ecore_config_bundle_local =
       ecore_config_bundle_new(__ecore_config_server_local, "config");
    __ecore_config_bundle_local->data = list;
-   free(temp);
 
    path = ecore_config_theme_default_path_get();
    ecore_config_string_default("/e/themes/search_path", path);
@@ -1647,3 +1549,33 @@
    return ret;
 }
 
+static inline void *
+__ecore_argb_to_long(int a, int r, int g, int b, long *v)
+{
+   *v = ((a << 24) & 0xff000000 )
+      | ((r << 16) &   0xff0000 )
+      | ((g <<  8) &     0xff00 )
+      | ( b        &       0xff );
+
+   return (void *)v;
+}
+
+static inline void *
+__ecore_argbstr_to_long(char *argb, long *v)
+{
+   char *l = NULL;
+
+   // convert hexadecimal string #..., #0x..., 0x..., ... to long
+   if(*argb == '#')
+     argb++;
+   *v = (long)strtoul( argb, &l, 16);
+
+   if(*l)
+     {
+       E(0, "ecore_config_val: value \"%s\" not a valid hexadecimal RGB 
value?\n", argb);
+       return NULL;
+     }
+
+   return (void *)v;
+}
+
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_db.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- ecore_config_db.c   6 Jan 2006 18:26:36 -0000       1.12
+++ ecore_config_db.c   8 Jan 2006 14:57:14 -0000       1.13
@@ -167,8 +167,10 @@
                  ecore_config_typed_set(key, (void *)&tmp, type);
                  break;
               }
-            case ECORE_CONFIG_STR:
             case ECORE_CONFIG_RGB:
+              ecore_config_argbstr_set(key, value);
+              break;
+            case ECORE_CONFIG_STR:
             case ECORE_CONFIG_THM:
               ecore_config_typed_set(key, (void *)value, type);
               break;
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_extra.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- ecore_config_extra.c        6 Jan 2006 18:26:36 -0000       1.8
+++ ecore_config_extra.c        8 Jan 2006 14:57:14 -0000       1.9
@@ -257,32 +257,6 @@
  * @param   desc      String description of property.
  * @return  @c ECORE_CONFIG_ERR_SUCC on success.
  * @ingroup Ecore_Config_Create_Group
- * @deprecated
- */
-int
-ecore_config_rgb_create(const char *key, char *val, char short_opt,
-                        char *long_opt, char *desc)
-{
-   char               *argb;
-   int                 ret;
-
-   argb = ecore_config_rgb_to_argb(val);
-   ret = ecore_config_argb_create(key, argb, short_opt, long_opt, desc);
-   free(argb);
-   return ret;
-}
-
-/**
- * Creates a new color property, if it does not already exist, and sets its
- * attributes to those given.
- * @param   key       The property key.
- * @param   val       Default color value of key, as a hexadecimal string.
- * @param   short_opt Short option used to set the property from command
- *                    line.
- * @param   long_opt  Long option used to set the property from command line.
- * @param   desc      String description of property.
- * @return  @c ECORE_CONFIG_ERR_SUCC on success.
- * @ingroup Ecore_Config_Create_Group
  */
 int
 ecore_config_argb_create(const char *key, char *val, char short_opt,




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to