From 20df2031055a920a433c4f0cd5287412c3443e35 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sat, 8 May 2004 03:10:45 +0000 Subject: [PATCH] ecore_config now formats like most of the rest of ecore!!! and - errr - handy - need to talk to you about function call names, and the use of "long's" :) SVN revision: 10112 --- .../ecore/src/lib/ecore_config/Ecore_Config.h | 315 +-- .../ecore/src/lib/ecore_config/convenience.c | 478 +++-- .../ecore/src/lib/ecore_config/ecore_config.c | 1818 +++++++++++------ legacy/ecore/src/lib/ecore_config/edb.c | 329 +-- legacy/ecore/src/lib/ecore_config/ipc.h | 59 +- legacy/ecore/src/lib/ecore_config/ipc_ecore.c | 550 ++--- legacy/ecore/src/lib/ecore_config/ipc_main.c | 572 +++--- legacy/ecore/src/lib/ecore_config/util.c | 996 +++++---- legacy/ecore/src/lib/ecore_config/util.h | 85 +- 9 files changed, 3104 insertions(+), 2098 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_config/Ecore_Config.h b/legacy/ecore/src/lib/ecore_config/Ecore_Config.h index 1bbdac9ad7..37d2491829 100644 --- a/legacy/ecore/src/lib/ecore_config/Ecore_Config.h +++ b/legacy/ecore/src/lib/ecore_config/Ecore_Config.h @@ -5,10 +5,6 @@ * @file * @brief Provides the Enlightened Property Library. * - * The Enlightened Property Library (Ecore_Config) is an adbstraction from the - * complexities of writing your own configuration. It provides many features - * using the Enlightenment 17 development libraries. - * * This file provies all headers and structs for use with Ecore_Config. * Using individual header files should not be necessary. */ @@ -41,137 +37,168 @@ /* structures */ -typedef enum Ecore_Config_Type { - PT_NIL=0, - PT_INT=1, - PT_FLT=2, - PT_STR=3, - PT_RGB=4, - PT_THM=5 +/** + * Valid configuration property types. + */ +typedef enum Ecore_Config_Type +{ + PT_NIL = 0, ///< Property with no value. + PT_INT = 1, ///< Integer property type. + PT_FLT = 2, ///< Float property type. + PT_STR = 3, ///< String property type. + PT_RGB = 4, ///< Colour property type. + PT_THM = 5 ///< Theme property type. } Ecore_Config_Type; - - -typedef enum Ecore_Config_Flag { - PF_NONE=0, - PF_BOUNDS=1, - PF_MODIFIED=2, - PF_SYSTEM=4 +typedef enum Ecore_Config_Flag +{ + PF_NONE = 0, + PF_BOUNDS = 1, + PF_MODIFIED = 2, + PF_SYSTEM = 4 } Ecore_Config_Flag; +/** + * Property change callback function prototype. + */ +typedef int (*Ecore_Config_Listener) (const char *key, + const Ecore_Config_Type type, + const int tag, void *data); - -typedef int (*Ecore_Config_Listener)(const char *key,const Ecore_Config_Type type,const int tag,void *data); - - -typedef struct Ecore_Config_Listener_List { - Ecore_Config_Listener listener; - const char *name; - void *data; - int tag; - struct Ecore_Config_Listener_List *next; } Ecore_Config_Listener_List; +typedef struct Ecore_Config_Listener_List +{ + Ecore_Config_Listener listener; + const char *name; + void *data; + int tag; + struct Ecore_Config_Listener_List *next; +} Ecore_Config_Listener_List; /** * The actual property for storing a key-value pair. */ -typedef struct Ecore_Config_Prop { - char *key; - char *description; - char short_opt; - char *long_opt; - char *ptr; - Ecore_Config_Type type; - long val,lo,hi,step; - Ecore_Config_Flag flags; - Ecore_Config_Listener_List *listeners; - void *data; - struct Ecore_Config_Prop *next; /**< pointer to the next property in the list */ - } Ecore_Config_Prop; +typedef struct Ecore_Config_Prop +{ + char *key; ///< Property key. + char *description; ///< Description set by ecore_config_descibe. + char short_opt; + char *long_opt; + char *ptr; ///< Used as the value when the property is a string or theme. + Ecore_Config_Type type; ///< Property type. + long val; ///< Used as the value when the property is an integer, float or colour. + long lo; ///< Lower bound for the value when the property is an integer or float. + long hi; ///< Higher bound for the value when the property is an integer or float. + long step; ///< Increment for the value when the property is an integer or float. + Ecore_Config_Flag flags; /// < Configuration flags. + Ecore_Config_Listener_List *listeners; ///< List of change listeners. + void *data; /// < Stores extra data for the property. + struct Ecore_Config_Prop *next; ///< Pointer to the next property in the list. +} Ecore_Config_Prop; -/** - * A container for a list of properties. Provided so that an application can - * use different set of properties at any time. This is useful for multiple - * window support. +/* + * A container for a list of properties. Provided so that an + * application can use different set of properties at any time. This + * is useful for multiple window support. */ -typedef struct Ecore_Config_Bundle { - char *identifier; /**< identifier for this set of properties (window ID for example) */ - char *owner; /**< this is used to store the application name related to the bundle */ - long serial; /**< unique identifier to identify bundle */ - Ecore_Config_Prop *data; /**< pointer to root of property list */ - void *user_data; /**< app specific pointer to "other data" */ - struct Ecore_Config_Bundle *next; /**< pointer to next bundle in this application */ - } Ecore_Config_Bundle; +typedef struct Ecore_Config_Bundle +{ + char *identifier; ///< Identifier for this set of properties (window ID for example) + char *owner; ///< This is used to store the application name related to the bundle + long serial; ///< Unique identifier to identify bundle + Ecore_Config_Prop *data; ///< Pointer to root of property list + void *user_data; ///< App specific pointer to "other data" + struct Ecore_Config_Bundle *next; ///< Pointer to next bundle in this application +} Ecore_Config_Bundle; -typedef struct Ecore_Config_Server { - void *server; - char *name; - Ecore_Config_Bundle *bundles; /* data anchor */ - struct Ecore_Config_Server *next; } Ecore_Config_Server; +typedef struct Ecore_Config_Server +{ + void *server; + char *name; + Ecore_Config_Bundle *bundles; /* data anchor */ + struct Ecore_Config_Server *next; +} Ecore_Config_Server; # ifdef __cplusplus -extern "C" { +extern "C" +{ # endif - + /* global ptrs to save passing them through the API */ -extern Ecore_Config_Server *__ecore_config_server_global; -extern Ecore_Config_Server *__ecore_config_server_local; -extern Ecore_Config_Bundle *__ecore_config_bundle_local; -extern char *__ecore_config_app_name; + extern Ecore_Config_Server *__ecore_config_server_global; + extern Ecore_Config_Server *__ecore_config_server_local; + extern Ecore_Config_Bundle *__ecore_config_bundle_local; + extern char *__ecore_config_app_name; -Ecore_Config_Prop *ecore_config_get(const char *key); -const char *ecore_config_get_type(const Ecore_Config_Prop *e); -void *ecore_config_get_data(const char *key); -char *ecore_config_get_string(const char *key); -long ecore_config_get_int(const char *key); -int ecore_config_get_rgb(const char *key,int *r, int *g, int *b); -float ecore_config_get_float(const char *key); -char *ecore_config_get_theme(const char *key); -char *ecore_config_get_as_string(const char *key); -int ecore_config_describe(const char *key, char *desc); -int ecore_config_set_short_opt(const char *key, char short_opt); -int ecore_config_set_long_opt(const char *key, char *long_opt); -int ecore_config_set(const char *key,char *val); -int ecore_config_set_typed(const char *key,void *val,int type); -int ecore_config_set_string(const char *key,char *val); -int ecore_config_set_int(const char *key,int val); -int ecore_config_set_rgb(const char *key,char *val); -char *ecore_config_get_rgbstr(const char *key); -int ecore_config_set_float(const char *key,float val); -int ecore_config_set_theme(const char *key,char *val); -int ecore_config_set_theme_preview_group(const char *key, char *group); -int ecore_config_set_as_string(const char *key,char *val); + Ecore_Config_Prop *ecore_config_get(const char *key); + const char *ecore_config_get_type(const Ecore_Config_Prop * e); + void *ecore_config_get_data(const char *key); + char *ecore_config_get_string(const char *key); + long ecore_config_get_int(const char *key); + int ecore_config_get_rgb(const char *key, int *r, int *g, + int *b); + float ecore_config_get_float(const char *key); + char *ecore_config_get_theme(const char *key); + char *ecore_config_get_as_string(const char *key); + int ecore_config_describe(const char *key, char *desc); + int ecore_config_set_short_opt(const char *key, + char short_opt); + int ecore_config_set_long_opt(const char *key, + char *long_opt); + int ecore_config_set(const char *key, char *val); + int ecore_config_set_typed(const char *key, void *val, + int type); + int ecore_config_set_string(const char *key, char *val); + int ecore_config_set_int(const char *key, int val); + int ecore_config_set_rgb(const char *key, char *val); + char *ecore_config_get_rgbstr(const char *key); + int ecore_config_set_float(const char *key, float val); + int ecore_config_set_theme(const char *key, char *val); + int ecore_config_set_theme_preview_group(const char *key, + char *group); + int ecore_config_set_as_string(const char *key, char *val); -int ecore_config_default(const char *key,char *val,float lo,float hi,float step); -int ecore_config_default_typed(const char *key,void *val,int type); -int ecore_config_default_int(const char *key,int val); -int ecore_config_default_int_bound(const char *key,int val,int lo,int hi,int step); -int ecore_config_default_string(const char *key,char *val); -int ecore_config_default_float(const char *key,float val); -int ecore_config_default_float_bound(const char *key,float val,float lo,float hi,float step); -int ecore_config_default_rgb(const char *key,char *val); -int ecore_config_default_theme(const char *key,char *val); + int ecore_config_default(const char *key, char *val, + float lo, float hi, float step); + int ecore_config_default_typed(const char *key, void *val, + int type); + int ecore_config_default_int(const char *key, int val); + int ecore_config_default_int_bound(const char *key, int val, + int lo, int hi, int step); + int ecore_config_default_string(const char *key, char *val); + int ecore_config_default_float(const char *key, float val); + int ecore_config_default_float_bound(const char *key, + float val, float lo, + float hi, float step); + int ecore_config_default_rgb(const char *key, char *val); + int ecore_config_default_theme(const char *key, char *val); -int ecore_config_listen(const char *name,const char *key,Ecore_Config_Listener listener,int tag,void *data); -int ecore_config_deaf(const char *name,const char *key,Ecore_Config_Listener listener); -Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop *e); -int ecore_config_guess_type(const char *key, char *val); + int ecore_config_listen(const char *name, const char *key, + Ecore_Config_Listener listener, + int tag, void *data); + int ecore_config_deaf(const char *name, const char *key, + Ecore_Config_Listener listener); + Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop * e); + int ecore_config_guess_type(const char *key, char *val); -Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server *srv, const char *id); -Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server *srv); -Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle *ns); -Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *srv, long serial); -Ecore_Config_Bundle *ecore_config_bundle_get_by_label(Ecore_Config_Server *srv, const char *label); -long ecore_config_bundle_get_serial(Ecore_Config_Bundle *ns); -char *ecore_config_bundle_get_label(Ecore_Config_Bundle *ns); - + Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server * srv, + const char *id); + Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server * srv); + Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle * ns); + Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server * + srv, long serial); + Ecore_Config_Bundle *ecore_config_bundle_get_by_label(Ecore_Config_Server * + srv, + const char *label); + long ecore_config_bundle_get_serial(Ecore_Config_Bundle * ns); + char *ecore_config_bundle_get_label(Ecore_Config_Bundle * ns); -int ecore_config_init(char *name); -int ecore_config_shutdown(void); + int ecore_config_init(char *name); + int ecore_config_shutdown(void); -int ecore_config_load(void); -int ecore_config_load_file(char *file); -int ecore_config_save(void); -int ecore_config_save_file(char *file); + int ecore_config_load(void); + int ecore_config_load_file(char *file); + int ecore_config_save(void); + int ecore_config_save_file(char *file); /* error codes */ # define ECORE_CONFIG_ERR_NOTSUPP (-16) @@ -185,33 +212,55 @@ int ecore_config_save_file(char *file); # define ECORE_CONFIG_ERR_PATHEX (-8) # define ECORE_CONFIG_ERR_TYPEMISMATCH (-7) # define ECORE_CONFIG_ERR_MUTEX (-6) -# define ECORE_CONFIG_ERR_NOTFOUND (-5) -# define ECORE_CONFIG_ERR_OOM (-4) -# define ECORE_CONFIG_ERR_IGNORED (-3) -# define ECORE_CONFIG_ERR_NODATA (-2) -# define ECORE_CONFIG_ERR_FAIL (-1) -# define ECORE_CONFIG_ERR_SUCC (0) +# define ECORE_CONFIG_ERR_NOTFOUND (-5) ///< Error indicating that the item searched for could not be found. +# define ECORE_CONFIG_ERR_OOM (-4) ///< Error given when the program runs out of memory. +# define ECORE_CONFIG_ERR_IGNORED (-3) ///< Error occurred, but was ignored. +# define ECORE_CONFIG_ERR_NODATA (-2) ///< Error given when necessary data is not provided. +# define ECORE_CONFIG_ERR_FAIL (-1) ///< Failure result. +# define ECORE_CONFIG_ERR_SUCC (0) ///< Success result. # define ECORE_CONFIG_PARSE_HELP (-2) # define ECORE_CONFIG_PARSE_EXIT (-1) # define ECORE_CONFIG_PARSE_CONTINUE (0) /* convenience mathods in convenience.c */ -int ecore_config_evas_font_path_apply(Evas *evas); -void ecore_config_args_display(void); -int ecore_config_args_parse(int argc, char **argv); -void ecore_config_app_describe(char *description); - -int ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, char *desc); -int ecore_config_create_typed(const char *key, void *val, int type, char short_opt, char *long_opt, char *desc); -int ecore_config_create_int(const char *key, int val, char short_opt, char *long_opt, char *desc); -int ecore_config_create_int_bound(const char *key, int val, int low, int high, int step, char short_opt, char *long_opt, char *desc); -int ecore_config_create_string(const char *key, char *val, char short_opt, char *long_opt, char *desc); -int ecore_config_create_float(const char *key, float val, char short_opt, char *long_opt, char *desc); -int ecore_config_create_float_bound(const char *key, float val, float low, float high, float step, char short_opt, char *long_opt, char *desc); -int ecore_config_create_rgb(const char *key, char *val, char short_opt, char *long_opt, char *desc); -int ecore_config_create_theme(const char *key, char *val, char short_opt, char *long_opt, char *desc); + int ecore_config_evas_font_path_apply(Evas * evas); + void ecore_config_args_display(void); + int ecore_config_args_parse(int argc, char **argv); + void ecore_config_app_describe(char *description); + int ecore_config_create(const char *key, void *val, + char short_opt, char *long_opt, + char *desc); + int ecore_config_create_typed(const char *key, void *val, + int type, char short_opt, + char *long_opt, char *desc); + int ecore_config_create_int(const char *key, int val, + char short_opt, char *long_opt, + char *desc); + int ecore_config_create_int_bound(const char *key, int val, + int low, int high, + int step, char short_opt, + char *long_opt, + char *desc); + int ecore_config_create_string(const char *key, char *val, + char short_opt, + char *long_opt, char *desc); + int ecore_config_create_float(const char *key, float val, + char short_opt, char *long_opt, + char *desc); + int ecore_config_create_float_bound(const char *key, + float val, float low, + float high, float step, + char short_opt, + char *long_opt, + char *desc); + int ecore_config_create_rgb(const char *key, char *val, + char short_opt, char *long_opt, + char *desc); + int ecore_config_create_theme(const char *key, char *val, + char short_opt, char *long_opt, + char *desc); # ifdef __cplusplus } diff --git a/legacy/ecore/src/lib/ecore_config/convenience.c b/legacy/ecore/src/lib/ecore_config/convenience.c index f7f880b7c9..2393604f56 100644 --- a/legacy/ecore/src/lib/ecore_config/convenience.c +++ b/legacy/ecore/src/lib/ecore_config/convenience.c @@ -4,236 +4,334 @@ #include #include -char *__ecore_config_app_description; +char *__ecore_config_app_description; + +extern int ecore_config_bound(Ecore_Config_Prop * e); -extern int ecore_config_bound(Ecore_Config_Prop *e); /* shorthand prop setup code to make client apps a little smaller ;) */ -int ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, char *desc) { - int type=ecore_config_guess_type(key, val); - return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc);} +int +ecore_config_create(const char *key, void *val, char short_opt, char *long_opt, + char *desc) +{ + int type = ecore_config_guess_type(key, val); -int ecore_config_create_typed(const char *key, void *val, int type, char short_opt, char *long_opt, char *desc) { - int ret; + return ecore_config_create_typed(key, val, type, short_opt, long_opt, desc); +} - if ((ret=ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC) - return ret; - if ((ret=ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC) - return ret; - if ((ret=ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC) - return ret; - ret=ecore_config_describe(key, desc); - return ret;} - -int ecore_config_create_int(const char *key, int val, char short_opt, char *long_opt, char *desc) { - return - ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc);} +int +ecore_config_create_typed(const char *key, void *val, int type, char short_opt, + char *long_opt, char *desc) +{ + int ret; -int ecore_config_create_int_bound(const char *key, int val, int low, int high, int step, char short_opt, char *long_opt, char *desc) { - Ecore_Config_Prop *e; - int ret; - ret= - ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc); - if (ret != ECORE_CONFIG_ERR_SUCC) - return ret; - e=ecore_config_get(key); - if (e) { - e->step=step; - e->flags|=PF_BOUNDS; - e->lo=low; - e->hi=high; - ecore_config_bound(e); - } - return ret;} + if ((ret = + ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC) + return ret; + if ((ret = + ecore_config_set_short_opt(key, short_opt)) != ECORE_CONFIG_ERR_SUCC) + return ret; + if ((ret = + ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC) + return ret; + ret = ecore_config_describe(key, desc); + return ret; +} -int ecore_config_create_string(const char *key, char *val, char short_opt, char *long_opt, char *desc) { - return - ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt, desc);} +int +ecore_config_create_int(const char *key, int val, char short_opt, + char *long_opt, char *desc) +{ + return + ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, + desc); +} -int ecore_config_create_float(const char *key, float val, char short_opt, char *long_opt, char *desc) { - return - ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc);} +int +ecore_config_create_int_bound(const char *key, int val, int low, int high, + int step, char short_opt, char *long_opt, + char *desc) +{ + Ecore_Config_Prop *e; + int ret; -int ecore_config_create_float_bound(const char *key, float val, float low, float high, float step, char short_opt, char *long_opt, char *desc) { - Ecore_Config_Prop *e; - int ret; - ret= - ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc); - e=ecore_config_get(key); - if (e) { - e->step=(int)(step*ECORE_CONFIG_FLOAT_PRECISION); - e->flags|=PF_BOUNDS; - e->lo=(int)(low*ECORE_CONFIG_FLOAT_PRECISION); - e->hi=(int)(high*ECORE_CONFIG_FLOAT_PRECISION); - ecore_config_bound(e); - } - return ret;} + ret = + ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, + desc); + if (ret != ECORE_CONFIG_ERR_SUCC) + return ret; + e = ecore_config_get(key); + if (e) + { + e->step = step; + e->flags |= PF_BOUNDS; + e->lo = low; + e->hi = high; + ecore_config_bound(e); + } + return ret; +} -int ecore_config_create_rgb(const char *key, char *val, char short_opt, char *long_opt, char *desc) { - return - ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt, desc);} +int +ecore_config_create_string(const char *key, char *val, char short_opt, + char *long_opt, char *desc) +{ + return + ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt, + desc); +} -int ecore_config_create_theme(const char *key, char *val, char short_opt, char *long_opt, char *desc) { - return - ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt, desc);} +int +ecore_config_create_float(const char *key, float val, char short_opt, + char *long_opt, char *desc) +{ + return + ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, + desc); +} + +int +ecore_config_create_float_bound(const char *key, float val, float low, + float high, float step, char short_opt, + char *long_opt, char *desc) +{ + Ecore_Config_Prop *e; + int ret; + + ret = + ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, + desc); + e = ecore_config_get(key); + if (e) + { + e->step = (int)(step * ECORE_CONFIG_FLOAT_PRECISION); + e->flags |= PF_BOUNDS; + e->lo = (int)(low * ECORE_CONFIG_FLOAT_PRECISION); + e->hi = (int)(high * ECORE_CONFIG_FLOAT_PRECISION); + ecore_config_bound(e); + } + return ret; +} + +int +ecore_config_create_rgb(const char *key, char *val, char short_opt, + char *long_opt, char *desc) +{ + return + ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt, + desc); +} + +int +ecore_config_create_theme(const char *key, char *val, char short_opt, + char *long_opt, char *desc) +{ + return + ecore_config_create_typed(key, (void *)val, PT_THM, short_opt, long_opt, + desc); +} /* this should only be built if evas is present */ +/** + * Calls evas_font_path_append on @evas for each of the font names stored + * in the property "/e/font/path". + * @param evas Evas object to append the font names to. + * @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA + * is returned if the property has not been set. + */ int -ecore_config_evas_font_path_apply (Evas * evas) +ecore_config_evas_font_path_apply(Evas * evas) { - char *font_path, *font_path_tmp, *ptr, *end; + char *font_path, *font_path_tmp, *ptr, *end; - font_path = ecore_config_get_string ("/e/font/path"); + font_path = ecore_config_get_string("/e/font/path"); - if (!font_path) - return ECORE_CONFIG_ERR_NODATA; - ptr = font_path; - end = font_path + strlen (font_path); - font_path_tmp = font_path; - while (ptr && ptr < end) - { - while (*ptr != '|' && ptr < end) - ptr++; - if (ptr < end) - *ptr = '\0'; + if (!font_path) + return ECORE_CONFIG_ERR_NODATA; + ptr = font_path; + end = font_path + strlen(font_path); + font_path_tmp = font_path; + while (ptr && ptr < end) + { + while (*ptr != '|' && ptr < end) + ptr++; + if (ptr < end) + *ptr = '\0'; - evas_font_path_append (evas, font_path_tmp); - ptr++; - font_path_tmp = ptr; - } + evas_font_path_append(evas, font_path_tmp); + ptr++; + font_path_tmp = ptr; + } - free (font_path); + free(font_path); - return ECORE_CONFIG_ERR_SUCC; + return ECORE_CONFIG_ERR_SUCC; } -static char *_ecore_config_short_types[]={ "nil", "int", "flt", "str", "rgb", "str"}; +static char *_ecore_config_short_types[] = + { "nil", "int", "flt", "str", "rgb", "str" }; +/** + * Prints the property list of the local configuration bundle to output. + */ void ecore_config_args_display(void) { - Ecore_Config_Prop *props; - - if (__ecore_config_app_description) - printf("%s\n\n", __ecore_config_app_description); - printf("Supported Options:\n"); - printf(" -h, --help\t Print this text\n"); - if (!__ecore_config_bundle_local) return; - props = __ecore_config_bundle_local->data; - while (props) - { - if (props->flags&PF_SYSTEM) { - props = props->next; - continue; - } - printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt?'-':' ', - props->short_opt?props->short_opt:' ', props->short_opt?',':' ', - props->long_opt?props->long_opt:props->key, - _ecore_config_short_types[props->type], - props->description?props->description:"(no description available)"); - - props = props->next; - } + Ecore_Config_Prop *props; + + if (__ecore_config_app_description) + printf("%s\n\n", __ecore_config_app_description); + printf("Supported Options:\n"); + printf(" -h, --help\t Print this text\n"); + if (!__ecore_config_bundle_local) + return; + props = __ecore_config_bundle_local->data; + while (props) + { + if (props->flags & PF_SYSTEM) + { + props = props->next; + continue; + } + printf(" %c%c%c --%s\t<%s> %s\n", props->short_opt ? '-' : ' ', + props->short_opt ? props->short_opt : ' ', + props->short_opt ? ',' : ' ', + props->long_opt ? props->long_opt : props->key, + _ecore_config_short_types[props->type], + props->description ? props-> + description : "(no description available)"); + + props = props->next; + } } int -ecore_config_parse_set(Ecore_Config_Prop *prop,char *arg,char *opt,char opt2) { - if (!arg) { - if (opt) - printf("Missing expected argument for option --%s\n", opt); - else - printf("Missing expected argument for option -%c\n", opt2); - return ECORE_CONFIG_PARSE_EXIT; - } else - ecore_config_set(prop->key, arg); - return ECORE_CONFIG_PARSE_CONTINUE; +ecore_config_parse_set(Ecore_Config_Prop * prop, char *arg, char *opt, + char opt2) +{ + if (!arg) + { + if (opt) + printf("Missing expected argument for option --%s\n", opt); + else + printf("Missing expected argument for option -%c\n", opt2); + return ECORE_CONFIG_PARSE_EXIT; + } + else + ecore_config_set(prop->key, arg); + return ECORE_CONFIG_PARSE_CONTINUE; } int ecore_config_args_parse(int argc, char **argv) { - int nextarg, next_short_opt, found, ret; - char *arg; - char *long_opt, short_opt; - Ecore_Config_Prop *prop; - - nextarg = 1; - while (nextarg < argc) { - arg = argv[nextarg]; + int nextarg, next_short_opt, found, ret; + char *arg; + char *long_opt, short_opt; + Ecore_Config_Prop *prop; - if (*arg != '-') { - printf("Unexpected attribute \"%s\"\n", arg); - nextarg++; - continue; - } - - next_short_opt = 1; - short_opt = *(arg + next_short_opt); + nextarg = 1; + while (nextarg < argc) + { + arg = argv[nextarg]; - if (short_opt == '-') { - long_opt = arg + 2; - - if (!strcmp(long_opt, "help")) { - ecore_config_args_display(); - return ECORE_CONFIG_PARSE_HELP; - } + if (*arg != '-') + { + printf("Unexpected attribute \"%s\"\n", arg); + nextarg++; + continue; + } - found = 0; - prop = __ecore_config_bundle_local->data; - while (prop) { - if ((prop->long_opt && !strcmp(long_opt, prop->long_opt)) - || !strcmp(long_opt, prop->key)) { - found = 1; - if ((ret=ecore_config_parse_set(prop, argv[++nextarg], long_opt,'\0')) - != ECORE_CONFIG_PARSE_CONTINUE); - return ret; - break; - } - prop = prop->next; - } - if (!found) { - printf("Unrecognised option \"%s\"\n", long_opt); - printf("Try using -h or --help for more information.\n\n"); - return ECORE_CONFIG_PARSE_EXIT; - } - } else { - while (short_opt) { - if (short_opt == 'h') { - ecore_config_args_display(); - return ECORE_CONFIG_PARSE_HELP; - } else { - found = 0; - prop = __ecore_config_bundle_local->data; - while (prop) { - if (short_opt == prop->short_opt) { - found = 1; - if ((ret=ecore_config_parse_set(prop, argv[++nextarg], NULL, short_opt)) - != ECORE_CONFIG_PARSE_CONTINUE) - return ret; - break; - } - prop = prop->next; - } - - if (!found) { - printf("Unrecognised option '%c'\n", short_opt); - printf("Try using -h or --help for more information.\n\n"); - return ECORE_CONFIG_PARSE_EXIT; - } - } - short_opt = *(arg + ++next_short_opt); - } - } - nextarg++; - } + next_short_opt = 1; + short_opt = *(arg + next_short_opt); - return ECORE_CONFIG_PARSE_CONTINUE; + if (short_opt == '-') + { + long_opt = arg + 2; + + if (!strcmp(long_opt, "help")) + { + ecore_config_args_display(); + return ECORE_CONFIG_PARSE_HELP; + } + + found = 0; + prop = __ecore_config_bundle_local->data; + while (prop) + { + if ((prop->long_opt && !strcmp(long_opt, prop->long_opt)) + || !strcmp(long_opt, prop->key)) + { + found = 1; + if ((ret = + ecore_config_parse_set(prop, argv[++nextarg], + long_opt, + '\0')) != + ECORE_CONFIG_PARSE_CONTINUE); + return ret; + break; + } + prop = prop->next; + } + if (!found) + { + printf("Unrecognised option \"%s\"\n", long_opt); + printf("Try using -h or --help for more information.\n\n"); + return ECORE_CONFIG_PARSE_EXIT; + } + } + else + { + while (short_opt) + { + if (short_opt == 'h') + { + ecore_config_args_display(); + return ECORE_CONFIG_PARSE_HELP; + } + else + { + found = 0; + prop = __ecore_config_bundle_local->data; + while (prop) + { + if (short_opt == prop->short_opt) + { + found = 1; + if ((ret = + ecore_config_parse_set(prop, + argv[++nextarg], + NULL, + short_opt)) != + ECORE_CONFIG_PARSE_CONTINUE) + return ret; + break; + } + prop = prop->next; + } + + if (!found) + { + printf("Unrecognised option '%c'\n", short_opt); + printf + ("Try using -h or --help for more information.\n\n"); + return ECORE_CONFIG_PARSE_EXIT; + } + } + short_opt = *(arg + ++next_short_opt); + } + } + nextarg++; + } + + return ECORE_CONFIG_PARSE_CONTINUE; } void -ecore_config_app_describe(char *description) { - if (__ecore_config_app_description) - free(__ecore_config_app_description); - __ecore_config_app_description = strdup(description); +ecore_config_app_describe(char *description) +{ + if (__ecore_config_app_description) + free(__ecore_config_app_description); + __ecore_config_app_description = strdup(description); } diff --git a/legacy/ecore/src/lib/ecore_config/ecore_config.c b/legacy/ecore/src/lib/ecore_config/ecore_config.c index b9bcd83a1d..4d8258c3db 100644 --- a/legacy/ecore/src/lib/ecore_config/ecore_config.c +++ b/legacy/ecore/src/lib/ecore_config/ecore_config.c @@ -16,321 +16,549 @@ Ecore_Config_Server *__ecore_config_server_global = NULL; Ecore_Config_Server *__ecore_config_server_local = NULL; Ecore_Config_Bundle *__ecore_config_bundle_local = NULL; -char *__ecore_config_app_name = NULL; +char *__ecore_config_app_name = NULL; Ecore_Config_Server *_ecore_config_ipc_init(char *name); -int _ecore_config_ipc_exit(void); +int _ecore_config_ipc_exit(void); -static char *_ecore_config_type[]={ "undefined", "integer", "float", "string", "colour", "theme" }; +static char *_ecore_config_type[] = + { "undefined", "integer", "float", "string", "colour", "theme" }; -Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop *e) { - Ecore_Config_Bundle *t; - Ecore_Config_Prop *p,*c; - Ecore_Config_Listener_List *l; - p=NULL; - c=e; - t = __ecore_config_bundle_local; +/** + * Removes the given property from the local configuration and destroys it. + * @param e Property to destroy. + * @return NULL + */ +Ecore_Config_Prop * +ecore_config_dst(Ecore_Config_Prop * e) +{ + Ecore_Config_Bundle *t; + Ecore_Config_Prop *p, *c; + Ecore_Config_Listener_List *l; - if(!e||!e->key) - return NULL; - if(t) { - if(t->data==e) - t->data=e->next; - else { - do { - p=c; - c=c->next; - } while(c&&(c!=e)); - if(c) /* remove from list if even in there */ - p->next=c->next; }} + p = NULL; + c = e; + t = __ecore_config_bundle_local; - while(e->listeners) { - l=e->listeners; - e->listeners=e->listeners->next; - free(l); } + if (!e || !e->key) + return NULL; + if (t) + { + if (t->data == e) + t->data = e->next; + else + { + do + { + p = c; + c = c->next; + } + while (c && (c != e)); + if (c) /* remove from list if even in there */ + p->next = c->next; + } + } - if(e->key) - free(e->key); - if(e->ptr&&(e->type==PT_STR)) - free(e->ptr); + while (e->listeners) + { + l = e->listeners; + e->listeners = e->listeners->next; + free(l); + } - memset(e,0,sizeof(Ecore_Config_Prop)); - free(e); + if (e->key) + free(e->key); + if (e->ptr && (e->type == PT_STR)) + free(e->ptr); - return NULL; } + memset(e, 0, sizeof(Ecore_Config_Prop)); + free(e); -Ecore_Config_Prop *ecore_config_get(const char *key) { - Ecore_Config_Bundle *t; - Ecore_Config_Prop *e; - - t = __ecore_config_bundle_local; - if(!t||!key) - return NULL; - e=t->data; - while(e) { - if(!strcmp(key,e->key)) - return e; - e=e->next; } - return NULL; } - - - -const char *ecore_config_get_type(const Ecore_Config_Prop *e) { - if(e) { - return _ecore_config_type[e->type]; } - return "not found"; } - - - -void *ecore_config_get_data(const char *key) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - return (e?((e->type==PT_STR)?((void *)&e->ptr):((void *)&e->val)) - :NULL); } - - -char *ecore_config_get_string(const char *key) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - return (e&&(e->type==PT_STR))?e->ptr:NULL; } - - -long ecore_config_get_int(const char *key) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - return (e&&((e->type==PT_INT)||(e->type==PT_RGB)))?e->val:0L; } - - -float ecore_config_get_float(const char *key) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - return (e&&(e->type==PT_FLT))?((float)e->val/ECORE_CONFIG_FLOAT_PRECISION):0.0; } - -int ecore_config_get_rgb(const char *key,int *r, int *g, int *b) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - - if(e&&((e->type==PT_RGB))) { - *r=(e->val>>16)&0xff; - *g=(e->val>>8)&0xff; - *b=e->val&0xff; - return ECORE_CONFIG_ERR_SUCC; } - return ECORE_CONFIG_ERR_FAIL; } - -char *ecore_config_get_rgbstr(const char *key) { - char *r; - r=NULL; - esprintf(&r,"#%06x",ecore_config_get_int(key)); - return r; } - -char *ecore_config_get_theme(const char *key) { - Ecore_Config_Prop *e; - e=ecore_config_get(key); - return (e&&(e->type==PT_THM))?e->ptr:NULL; } - - -char *ecore_config_get_as_string(const char *key) { - Ecore_Config_Prop *e; - char *r; - r=NULL; - if(!(e=ecore_config_get(key))) - E(0,"no such property, \"%s\"...\n",key); - else { - const char *type=ecore_config_get_type(e); - switch(e->type) { - case PT_NIL: - esprintf(&r,"%s:%s=",key,type); break; - case PT_INT: - esprintf(&r,"%s:%s=%ld",key,type,ecore_config_get_int(key)); break; - case PT_FLT: - esprintf(&r,"%s:%s=%lf",key,type,ecore_config_get_float(key)); break; - case PT_STR: - esprintf(&r,"%s:%s=\"%s\"",key,type,ecore_config_get_string(key)); break; - case PT_RGB: - esprintf(&r,"%s:%s=#%06x",key,type,ecore_config_get_int(key)); break; - case PT_THM: - esprintf(&r,"%s:%s=\"%s\"",key,type,ecore_config_get_theme(key)); break; - default: - esprintf(&r,"%s:unknown_type",key); break; }} - return r; } - - -int ecore_config_bound(Ecore_Config_Prop *e) { - int ret; - long v; - ret=ECORE_CONFIG_ERR_SUCC; - - if(!e) - return ECORE_CONFIG_ERR_FAIL; - if(e->flags&PF_BOUNDS) { - if((e->vallo)) { - E(0,"ecore_config_bounds(\"%s\",%ld): value out of range; adjusted to %ld...\n",e->key,e->val,e->lo); - e->val=e->lo; } - else if((e->val>e->hi)) { - E(0,"ecore_config_bounds(\"%s\",%ld): value out of range; adjusted to %ld...\n",e->key,e->val,e->hi); - e->val=e->hi; } - else - ret=ECORE_CONFIG_ERR_IGNORED; } - else - ret=ECORE_CONFIG_ERR_IGNORED; - - if(e->step) { - v=((int)(e->val/e->step))*e->step; - if(v!=e->val) { - if(e->type==PT_FLT) - E(0,"ecore_config_bound(\"%s\"): float value %f not a multiple of %f, adjusted to %f...\n", - e->key,((double)e->val)/ECORE_CONFIG_FLOAT_PRECISION,((double)e->step)/ECORE_CONFIG_FLOAT_PRECISION,((double)v)/ECORE_CONFIG_FLOAT_PRECISION); - else - E(0,"ecore_config_bound(\"%s\"): integer value %ld not a multiple of %ld, adjusted to %ld...\n", - e->key,e->val,e->step,v); - ret=ECORE_CONFIG_ERR_SUCC; - e->val=v; }} - - return ret; } - -int ecore_config_guess_type(const char *key,char *val) { - Ecore_Config_Prop *p; - char *l; - long v; - l=NULL; - - if ((p=ecore_config_get(key)) && p->type!=PT_NIL) - return p->type; - - if(!val) - return PT_NIL; - if (val[0]=='#') - return PT_RGB; - v=strtol(val,&l,10); - if(*l) { - float f; - if (sscanf(val,"%f%*s",&f)!=1) - return PT_STR; - return PT_FLT; - } - return PT_INT; - } - -static int ecore_config_val_typed(Ecore_Config_Prop *e,void *val,int type) { - char *l; - long v; - int *i; - float *f; - - l=NULL; - v=0; - - if(!(val)) - e->ptr=NULL; - else { - if (type==PT_INT) { - i = (int *)val; - e->val=(long)*i; - e->type=PT_INT; - } else if (type==PT_STR || type==PT_THM) { - if(!(e->ptr=strdup(val))) - return ECORE_CONFIG_ERR_OOM; - if (e->type==PT_NIL) - e->type=type; - } else if (type==PT_RGB) { - if (((char *)val)[0]=='#') { - if((v=strtol(&((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=PT_RGB; - } - } else if (type==PT_FLT) { - f = (float *)val; - e->val=(long)((*f)*ECORE_CONFIG_FLOAT_PRECISION); - e->type=PT_FLT; - } else - e->type=PT_NIL; - - ecore_config_bound(e); - e->flags|=PF_MODIFIED; - return ECORE_CONFIG_ERR_SUCC; - } - return ECORE_CONFIG_ERR_IGNORED; + return NULL; } -static int ecore_config_add_typed(const char *key, void* val, int type) { - Ecore_Config_Prop *e; - Ecore_Config_Bundle *t; +/** + * Returns the property of the config bundle with the given key. + * @param t Ecore_Config_Bundle to search. + * @param key The unique name of the wanted property. + * @return The property that corresponds to tnhe given key. NULL if the key + * could not be found. + */ +Ecore_Config_Prop * +ecore_config_get(const char *key) +{ + Ecore_Config_Bundle *t; + Ecore_Config_Prop *e; - t=__ecore_config_bundle_local; - if (!key) - return ECORE_CONFIG_ERR_NODATA; + t = __ecore_config_bundle_local; + if (!t || !key) + return NULL; + e = t->data; + while (e) + { + if (!strcmp(key, e->key)) + return e; + e = e->next; + } + return NULL; +} - if(!(e=malloc(sizeof(Ecore_Config_Prop)))) - goto ret; - memset(e,0,sizeof(Ecore_Config_Prop)); +/** + * Returns the type of the property. + * @param e Property to get the type of. + * @returns The type of the property. If the property is invalid, then the + * string "not found" is returned. + */ +const char * +ecore_config_get_type(const Ecore_Config_Prop * e) +{ + if (e) + { + return _ecore_config_type[e->type]; + } + return "not found"; +} - if(!(e->key=strdup(key))) - goto ret_free_nte; +/** + * Obtains the data pointed to by the specified property. + * @param key The property key. + * @return Data pointer used by the property. + */ +void * +ecore_config_get_data(const char *key) +{ + Ecore_Config_Prop *e; - if(!val) - e->type=PT_NIL; - else if(ecore_config_val_typed(e,val,type)==ECORE_CONFIG_ERR_OOM) - goto ret_free_key; + e = ecore_config_get(key); + return (e ? ((e->type == PT_STR) ? ((void *)&e->ptr) : ((void *)&e->val)) + : NULL); +} - e->next=t?t->data:NULL; - if(t) t->data=e; +/** + * Returns the specified property as a string. + * @param key The property key. + * @return The string value of the property. The function returns NULL if the + * property is not a string or is not set. + */ +char * +ecore_config_get_string(const char *key) +{ + Ecore_Config_Prop *e; - return ECORE_CONFIG_ERR_SUCC; + e = ecore_config_get(key); + return (e && (e->type == PT_STR)) ? e->ptr : NULL; +} - ret_free_key: - free(e->key); - ret_free_nte: - free(e); - ret: - return ECORE_CONFIG_ERR_OOM; } - +/** + * Returns the specified property as a long integer. + * @param key The property key. + * @return The integer value of the property. The function returns 0 if the + * property is not an integer or is not set. + */ +long +ecore_config_get_int(const char *key) +{ + Ecore_Config_Prop *e; -static int ecore_config_add(const char *key,char *val) { - int type; - type=ecore_config_guess_type(key, val); - return ecore_config_add_typed(key,val,type); } + e = ecore_config_get(key); + return (e && ((e->type == PT_INT) || (e->type == PT_RGB))) ? e->val : 0L; +} -int ecore_config_describe(const char *key, char *desc) { - Ecore_Config_Prop *e; - if (!(e=ecore_config_get(key))) - return ECORE_CONFIG_ERR_NODATA; - e->description = strdup(desc); - return ECORE_CONFIG_ERR_SUCC;} +/** + * Returns the specified property as a float. + * @param key The property key. + * @return The float value of the property. The function returns 0.0 if the + * property is not a float or is not set. + */ +float +ecore_config_get_float(const char *key) +{ + Ecore_Config_Prop *e; -int ecore_config_set_short_opt(const char *key, char short_opt) { - Ecore_Config_Prop *e; - if (!(e=ecore_config_get(key))) - return ECORE_CONFIG_ERR_NODATA; - e->short_opt = short_opt; - return ECORE_CONFIG_ERR_SUCC;} + e = ecore_config_get(key); + return (e + && (e->type == + PT_FLT)) ? ((float)e->val / ECORE_CONFIG_FLOAT_PRECISION) : 0.0; +} -int ecore_config_set_long_opt(const char *key, char *long_opt) { - Ecore_Config_Prop *e; - if (!(e=ecore_config_get(key))) - return ECORE_CONFIG_ERR_NODATA; - if (e->long_opt) - free (e->long_opt); - e->long_opt = strdup(long_opt); - return ECORE_CONFIG_ERR_SUCC;} +/** + * 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 @a ECORE_CONFIG_ERR_SUCC on success. @a ECORE_CONFIG_ERR_FAIL + * otherwise. + */ +int +ecore_config_get_rgb(const char *key, int *r, int *g, int *b) +{ + Ecore_Config_Prop *e; -int ecore_config_set_typed(const char *key,void *val,int type) { - Ecore_Config_Prop *e; - Ecore_Config_Listener_List *l; - int ret; + e = ecore_config_get(key); - if (!key) - return ECORE_CONFIG_ERR_NODATA; + if (e && ((e->type == PT_RGB))) + { + *r = (e->val >> 16) & 0xff; + *g = (e->val >> 8) & 0xff; + *b = e->val & 0xff; + return ECORE_CONFIG_ERR_SUCC; + } + return ECORE_CONFIG_ERR_FAIL; +} + +/** + * 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. + */ +char * +ecore_config_get_rgbstr(const char *key) +{ + char *r; + + r = NULL; + esprintf(&r, "#%06x", ecore_config_get_int(key)); + return r; +} + +/** + * Returns a theme property. + * @param key The property key. + * @return The name of the theme the property refers to. The function returns + * NULL if the property is not a theme or is not set. + */ +char * +ecore_config_get_theme(const char *key) +{ + Ecore_Config_Prop *e; + + e = ecore_config_get(key); + return (e && (e->type == PT_THM)) ? e->ptr : NULL; +} + +/** + * Retrieves the key as a string. + * @param key The property key. + * @return Returns a character array in the form of 'key:type=value'. NULL is + * returned if the property does not exist. + */ +char * +ecore_config_get_as_string(const char *key) +{ + Ecore_Config_Prop *e; + char *r; + + r = NULL; + if (!(e = ecore_config_get(key))) + E(0, "no such property, \"%s\"...\n", key); + else + { + const char *type = ecore_config_get_type(e); + + switch (e->type) + { + case PT_NIL: + esprintf(&r, "%s:%s=", key, type); + break; + case PT_INT: + esprintf(&r, "%s:%s=%ld", key, type, ecore_config_get_int(key)); + break; + case PT_FLT: + esprintf(&r, "%s:%s=%lf", key, type, ecore_config_get_float(key)); + break; + case PT_STR: + esprintf(&r, "%s:%s=\"%s\"", key, type, + ecore_config_get_string(key)); + break; + case PT_RGB: + esprintf(&r, "%s:%s=#%06x", key, type, ecore_config_get_int(key)); + break; + case PT_THM: + esprintf(&r, "%s:%s=\"%s\"", key, type, + ecore_config_get_theme(key)); + break; + default: + esprintf(&r, "%s:unknown_type", key); + break; + } + } + return r; +} + +int +ecore_config_bound(Ecore_Config_Prop * e) +{ + int ret; + long v; + + ret = ECORE_CONFIG_ERR_SUCC; + + if (!e) + return ECORE_CONFIG_ERR_FAIL; + if (e->flags & PF_BOUNDS) + { + if ((e->val < e->lo)) + { + E(0, + "ecore_config_bounds(\"%s\",%ld): value out of range; adjusted to %ld...\n", + e->key, e->val, e->lo); + e->val = e->lo; + } + else if ((e->val > e->hi)) + { + E(0, + "ecore_config_bounds(\"%s\",%ld): value out of range; adjusted to %ld...\n", + e->key, e->val, e->hi); + e->val = e->hi; + } + else + ret = ECORE_CONFIG_ERR_IGNORED; + } + else + ret = ECORE_CONFIG_ERR_IGNORED; + + if (e->step) + { + v = ((int)(e->val / e->step)) * e->step; + if (v != e->val) + { + if (e->type == PT_FLT) + E(0, + "ecore_config_bound(\"%s\"): float value %f not a multiple of %f, adjusted to %f...\n", + e->key, ((double)e->val) / ECORE_CONFIG_FLOAT_PRECISION, + ((double)e->step) / ECORE_CONFIG_FLOAT_PRECISION, + ((double)v) / ECORE_CONFIG_FLOAT_PRECISION); + else + E(0, + "ecore_config_bound(\"%s\"): integer value %ld not a multiple of %ld, adjusted to %ld...\n", + e->key, e->val, e->step, v); + ret = ECORE_CONFIG_ERR_SUCC; + e->val = v; + } + } + + return ret; +} + +/** + * Tries to guess the type of a property. + * + * This function first checks to see if the property exists. If it does, then + * the type of the stored property is returned. Otherwise, the function tries + * to guess the type of the property based on @a val. + * + * @param key The property key. + * @param val The value in string form. + * @return The type of the property determined by the function. Note that if + * val is NULL, PT_NIL will be returned. + */ +int +ecore_config_guess_type(const char *key, char *val) +{ + Ecore_Config_Prop *p; + char *l; + long v; + + l = NULL; + + if ((p = ecore_config_get(key)) && p->type != PT_NIL) + return p->type; + + if (!val) + return PT_NIL; + if (val[0] == '#') + return PT_RGB; + v = strtol(val, &l, 10); + if (*l) + { + float f; + + if (sscanf(val, "%f%*s", &f) != 1) + return PT_STR; + return PT_FLT; + } + return PT_INT; +} + +static int +ecore_config_val_typed(Ecore_Config_Prop * e, void *val, int type) +{ + char *l; + long v; + int *i; + float *f; + + l = NULL; + v = 0; + + if (!(val)) + e->ptr = NULL; + else + { + if (type == PT_INT) + { + i = (int *)val; + e->val = (long)*i; + e->type = PT_INT; + } + else if (type == PT_STR || type == PT_THM) + { + if (!(e->ptr = strdup(val))) + return ECORE_CONFIG_ERR_OOM; + if (e->type == PT_NIL) + e->type = type; + } + else if (type == PT_RGB) + { + if (((char *)val)[0] == '#') + { + if ((v = strtol(&((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 = PT_RGB; + } + } + else if (type == PT_FLT) + { + f = (float *)val; + e->val = (long)((*f) * ECORE_CONFIG_FLOAT_PRECISION); + e->type = PT_FLT; + } + else + e->type = PT_NIL; + + ecore_config_bound(e); + e->flags |= PF_MODIFIED; + return ECORE_CONFIG_ERR_SUCC; + } + return ECORE_CONFIG_ERR_IGNORED; +} + +static int +ecore_config_add_typed(const char *key, void *val, int type) +{ + Ecore_Config_Prop *e; + 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))) + goto ret_free_nte; + + if (!val) + e->type = PT_NIL; + else if (ecore_config_val_typed(e, val, type) == ECORE_CONFIG_ERR_OOM) + goto ret_free_key; + + e->next = t ? t->data : NULL; + if (t) + t->data = e; + + return ECORE_CONFIG_ERR_SUCC; + + ret_free_key: + free(e->key); + ret_free_nte: + free(e); + ret: + return ECORE_CONFIG_ERR_OOM; +} + +static int +ecore_config_add(const char *key, char *val) +{ + int type; + + type = ecore_config_guess_type(key, val); + return ecore_config_add_typed(key, val, type); +} + +/** + * Sets the description field of the indicated property. + * @param key The property key. + * @param desc Description string. + * @note The description string is copied for the property's use. You can + * free @a desc once this function is called. + */ +int +ecore_config_describe(const char *key, char *desc) +{ + Ecore_Config_Prop *e; + + if (!(e = ecore_config_get(key))) + return ECORE_CONFIG_ERR_NODATA; + e->description = strdup(desc); + return ECORE_CONFIG_ERR_SUCC; +} + +int +ecore_config_set_short_opt(const char *key, char short_opt) +{ + Ecore_Config_Prop *e; + + if (!(e = ecore_config_get(key))) + return ECORE_CONFIG_ERR_NODATA; + e->short_opt = short_opt; + return ECORE_CONFIG_ERR_SUCC; +} + +int +ecore_config_set_long_opt(const char *key, char *long_opt) +{ + Ecore_Config_Prop *e; + + if (!(e = ecore_config_get(key))) + return ECORE_CONFIG_ERR_NODATA; + if (e->long_opt) + free(e->long_opt); + e->long_opt = strdup(long_opt); + return ECORE_CONFIG_ERR_SUCC; +} + +/** + * Sets the indicated property to the given value and type. + * @param t Configuration bundle to use. + * @param key The property key. + * @param val A pointer to the value to set the property to. + * @param type The type of the property. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_typed(const char *key, void *val, int type) +{ + Ecore_Config_Prop *e; + Ecore_Config_Listener_List *l; + int ret; + + if (!key) + return ECORE_CONFIG_ERR_NODATA; /* if (!t) { * global prop * e=ecore_config_get(key); if (e) @@ -339,368 +567,702 @@ int ecore_config_set_typed(const char *key,void *val,int type) { return ECORE_CONFIG_ERR_SUCC; } */ - if (!(e=ecore_config_get(key))) - return ecore_config_add_typed(key,val,type); + if (!(e = ecore_config_get(key))) + return ecore_config_add_typed(key, val, type); - if ((ret=ecore_config_val_typed(e,val,type))==ECORE_CONFIG_ERR_SUCC) { - for(l=e->listeners;l;l=l->next) - l->listener(e->key,e->type,l->tag,l->data); - } - else { - E(0,"ecore_config_set_typed(\"%s\"): ecore_config_val_typed() failed: %d\n",key,ret); - } + if ((ret = ecore_config_val_typed(e, val, type)) == ECORE_CONFIG_ERR_SUCC) + { + for (l = e->listeners; l; l = l->next) + l->listener(e->key, e->type, l->tag, l->data); + } + else + { + E(0, + "ecore_config_set_typed(\"%s\"): ecore_config_val_typed() failed: %d\n", + key, ret); + } - return ret; - } - -int ecore_config_set(const char *key,char *val) { - int type; - int tmpi; - float tmpf; - type=ecore_config_guess_type(key, val); - if (type == PT_INT) { - tmpi = atoi(val); - return ecore_config_set_typed(key,(void*) &tmpi,type); - } else if (type == PT_FLT) { - tmpf = atof(val); - return ecore_config_set_typed(key,(void*) &tmpf,type); - } else - return ecore_config_set_typed(key,(void*) val,type); } - -int ecore_config_set_as_string(const char *key,char *val) { - return ecore_config_set(key,val); } - -int ecore_config_set_int(const char *key, int val) { - return ecore_config_set_typed(key,(void *)&val,PT_INT); } - -int ecore_config_set_string(const char *key, char* val) { - return ecore_config_set_typed(key,(void *)val,PT_STR); } - -int ecore_config_set_float(const char *key, float val) { - return ecore_config_set_typed(key,(void *)&val,PT_FLT); } - -int ecore_config_set_rgb(const char *key, char* val) { - return ecore_config_set_typed(key,(void *)val,PT_RGB); } - -int ecore_config_set_theme(const char *key, char* val) { - return ecore_config_set_typed(key,(void *)val,PT_THM); } - -int ecore_config_set_theme_preview_group(const char *key, char *group) { - int ret; - Ecore_Config_Prop *e; - - ret=ECORE_CONFIG_ERR_SUCC; - if(!(e=ecore_config_get(key))) { /* prop doesn't exist yet */ - if((ret=ecore_config_add_typed(key,"",PT_THM))!=ECORE_CONFIG_ERR_SUCC) /* try to add it */ - return ret; /* ...failed */ - if(!(e=ecore_config_get(key))) /* get handle */ - return ECORE_CONFIG_ERR_FAIL; - } - if (e->data) free(e->data); - e->data=strdup(group); - - return ret; } - -int ecore_config_default_typed(const char *key,void *val,int type) { - int ret; - Ecore_Config_Prop *e; - ret=ECORE_CONFIG_ERR_SUCC; - - if(!(e=ecore_config_get(key))) { /* prop doesn't exist yet */ - if((ret=ecore_config_add_typed(key,val,type))!=ECORE_CONFIG_ERR_SUCC) /* try to add it */ - return ret; /* ...failed */ - if(!(e=ecore_config_get(key))) /* get handle */ - return ECORE_CONFIG_ERR_FAIL; - e->flags=e->flags&~PF_MODIFIED; } - - return ret; } - -int ecore_config_default(const char *key,char *val,float lo,float hi,float step) { - int ret, type; - Ecore_Config_Prop *e; - - type=ecore_config_guess_type(key, val); - ret=ecore_config_default_typed(key, val, type); - e=ecore_config_get(key); - if (e) { - if (type==PT_INT) { - e->step=step; - e->flags|=PF_BOUNDS; - e->lo=lo; - e->hi=hi; - ecore_config_bound(e); - } else if (type==PT_FLT) { - e->step=(int)(step*ECORE_CONFIG_FLOAT_PRECISION); - e->flags|=PF_BOUNDS; - e->lo=(int)(lo*ECORE_CONFIG_FLOAT_PRECISION); - e->hi=(int)(hi*ECORE_CONFIG_FLOAT_PRECISION); - ecore_config_bound(e); - } - } - - return ret; -} - -int ecore_config_default_int(const char *key,int val) { - return ecore_config_default_typed(key, (void *) &val, PT_INT); + return ret; } -int ecore_config_default_int_bound(const char *key,int val,int low,int high,int step) { - Ecore_Config_Prop *e; - int ret; - - ret=ecore_config_default_typed(key, (void *) &val, PT_INT); - e=ecore_config_get(key); - if (e) { - e->step=step; - e->flags|=PF_BOUNDS; - e->lo=low; - e->hi=high; - ecore_config_bound(e); - } - - return ret; +/** + * Sets the indicated property to the value indicated by @a val. + * @param t Configuration bundle to use. + * @param key The property key. + * @param val String representation of value to set. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set(const char *key, char *val) +{ + int type; + int tmpi; + float tmpf; + + type = ecore_config_guess_type(key, val); + if (type == PT_INT) + { + tmpi = atoi(val); + return ecore_config_set_typed(key, (void *)&tmpi, type); + } + else if (type == PT_FLT) + { + tmpf = atof(val); + return ecore_config_set_typed(key, (void *)&tmpf, type); + } + else + return ecore_config_set_typed(key, (void *)val, type); } -int ecore_config_default_string(const char *key,char *val) { - return ecore_config_default_typed(key, (void *) val, PT_STR); +/** + * Sets the indicated property to the value given in the string. + * @param key The property key. + * @param val String representation of the value. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_as_string(const char *key, char *val) +{ + return ecore_config_set(key, val); } -int ecore_config_default_float(const char *key,float val){ - return ecore_config_default_typed(key, (void *) &val, PT_FLT); -} - -int ecore_config_default_float_bound(const char *key,float val,float low,float high,float step) { - Ecore_Config_Prop *e; - int ret; - - ret=ecore_config_default_typed(key, (void *) &val, PT_FLT); - e=ecore_config_get(key); - if (e) { - e->step=(int)(step*ECORE_CONFIG_FLOAT_PRECISION); - e->flags|=PF_BOUNDS; - e->lo=(int)(low*ECORE_CONFIG_FLOAT_PRECISION); - e->hi=(int)(high*ECORE_CONFIG_FLOAT_PRECISION); - ecore_config_bound(e); - } - - return ret; +/** + * Sets the indicated property to the given integer. + * @param key The property key. + * @param val Integer to set the property to. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_int(const char *key, int val) +{ + return ecore_config_set_typed(key, (void *)&val, PT_INT); } -int ecore_config_default_rgb(const char *key,char *val) { - return ecore_config_default_typed(key, (void *) val, PT_RGB); +/** + * Sets the indicated property to the given string. + * @param key The property key. + * @param val String to set the property to. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_string(const char *key, char *val) +{ + return ecore_config_set_typed(key, (void *)val, PT_STR); } -int ecore_config_default_theme(const char *key,char *val) { - return ecore_config_default_typed(key, (void *) val, PT_THM); +/** + * Sets the indicated property to the given float value. + * @param key The property key. + * @param val Float to set the property to. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_float(const char *key, float val) +{ + return ecore_config_set_typed(key, (void *)&val, PT_FLT); } - -int ecore_config_listen(const char *name,const char *key, - Ecore_Config_Listener listener,int tag,void *data) { - Ecore_Config_Prop *e; - Ecore_Config_Listener_List *l; - - if(!key) - return ECORE_CONFIG_ERR_NODATA; - - if(!(e=ecore_config_get(key))) { - int ret=ecore_config_add(key,""); - if(ret!=ECORE_CONFIG_ERR_SUCC) { - E(0,"ecore_config_listen: ecore_config_add(\"%s\") failed: %d\n",key,ret); - return ret; } - if(!(e=ecore_config_get(key))) { - E(0,"ecore_config_listen: list of properties corrupted!?\n"); - return ECORE_CONFIG_ERR_FAIL; }} - - for(l=e->listeners;l;l=l->next) - if(!strcmp(l->name,name)||(l->listener==listener)) { - E(1,"ecore_config_listen: %s is already listening for changes of %s in %s...\n", - name,key,t->identifier?t->identifier:""); - return ECORE_CONFIG_ERR_IGNORED; } - - if(!(l=malloc(sizeof(Ecore_Config_Listener_List)))) - return ECORE_CONFIG_ERR_OOM; - - E(1,"registering listener \"%s\" for \"%s\" (%d)...\n",name,key,e->type); - - memset(l,0,sizeof(Ecore_Config_Listener_List)); - - l->listener =listener; - l->name =name; - l->data =data; - l->tag =tag; - l->next =e->listeners; - e->listeners=l; - - if(e->type!=PT_NIL) /* call right on creation if prop exists and has val */ - listener(key,e->type,tag,data); - - return ECORE_CONFIG_ERR_SUCC; } - -int ecore_config_deaf(const char *name,const char *key, - Ecore_Config_Listener listener) { - Ecore_Config_Prop *e; - Ecore_Config_Listener_List *l,*p; - int ret; - ret=ECORE_CONFIG_ERR_NOTFOUND; - - if(!key) - return ECORE_CONFIG_ERR_NODATA; - - if(!(e=ecore_config_get(key))) - return ECORE_CONFIG_ERR_NOTFOUND; - - for(p=NULL,l=e->listeners;l;p=l,l=l->next) { - if((name&&!strcmp(l->name,name))||(l->listener==listener)) { - ret=ECORE_CONFIG_ERR_SUCC; - if(!p) - e->listeners=e->listeners->next; - else - p->next=l->next; - memset(l,0,sizeof(Ecore_Config_Listener)); - free(l); }} - - return ret; } - -Ecore_Config_Bundle *ecore_config_bundle_get_1st(Ecore_Config_Server *srv) { /* anchor: global, but read-only */ - return srv->bundles; } - -Ecore_Config_Bundle *ecore_config_bundle_get_next(Ecore_Config_Bundle *ns) { - return ns?ns->next:NULL; } - -Ecore_Config_Bundle *ecore_config_bundle_get_by_serial(Ecore_Config_Server *srv, long serial) { - Ecore_Config_Bundle *eb; - eb=srv->bundles; - - if(serial<0) - return NULL; - else if(serial==0) { - Ecore_Config_Bundle *r=eb; - return r; } - - while(eb) { - if(eb->serial==serial) - return eb; - eb=eb->next; } - return NULL; } - -Ecore_Config_Bundle *ecore_config_bundle_get_by_label(Ecore_Config_Server *srv, const char *label) { - Ecore_Config_Bundle *ns; - ns=srv->bundles; - - while(ns) { - if(ns->identifier&&!strcmp(ns->identifier,label)) - return ns; - ns=ns->next; } - return NULL; } - - -long ecore_config_bundle_get_serial(Ecore_Config_Bundle *ns) { - return ns?ns->serial:-1; } - -char *ecore_config_bundle_get_label(Ecore_Config_Bundle *ns) { - return ns?ns->identifier:NULL; } - - -Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server *srv,const char *identifier) { - Ecore_Config_Bundle *t; - static long ss; - ss=0; /* bundle unique serial */ - - if((t=malloc(sizeof(Ecore_Config_Bundle)))) { - memset(t,0,sizeof(Ecore_Config_Bundle)); - - t->identifier=(char *)identifier; - t->serial=++ss; - t->owner=srv->name; - t->next=srv->bundles; - srv->bundles=t; - } - return t; } - -Ecore_Config_Server *do_init(char *name) { - return _ecore_config_ipc_init(name); +/** + * Sets the indicated property to a color value. + * @param key The property key + * @param val Color value in RGB format. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_rgb(const char *key, char *val) +{ + return ecore_config_set_typed(key, (void *)val, PT_RGB); } -Ecore_Config_Server *ecore_config_init_local(char *name) { - char *p; - char *buf; +/** + * Sets the indicated property to a theme name. + * @param key The property key. + * @param val String giving the name of the theme. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_set_theme(const char *key, char *val) +{ + return ecore_config_set_typed(key, (void *)val, PT_THM); +} - if((p=getenv("HOME"))) { /* debug-only ### FIXME */ - if (!(buf=malloc(PATH_MAX*sizeof(char)))) +/** + * Sets the theme preview group of an indicated property. + * @param key The property key. + * @param group The group name. + * @return ECORE_CONFIG_ERR_SUCC on success. + */ +int +ecore_config_set_theme_preview_group(const char *key, char *group) +{ + int ret; + Ecore_Config_Prop *e; + + ret = ECORE_CONFIG_ERR_SUCC; + if (!(e = ecore_config_get(key))) + { /* prop doesn't exist yet */ + if ((ret = ecore_config_add_typed(key, "", PT_THM)) != ECORE_CONFIG_ERR_SUCC) /* try to add it */ + return ret; /* ...failed */ + if (!(e = ecore_config_get(key))) /* get handle */ + return ECORE_CONFIG_ERR_FAIL; + } + if (e->data) + free(e->data); + e->data = strdup(group); + + return ret; +} + +int +ecore_config_default_typed(const char *key, void *val, int type) +{ + int ret; + Ecore_Config_Prop *e; + + ret = ECORE_CONFIG_ERR_SUCC; + + if (!(e = ecore_config_get(key))) + { /* prop doesn't exist yet */ + if ((ret = ecore_config_add_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC) /* try to add it */ + return ret; /* ...failed */ + if (!(e = ecore_config_get(key))) /* get handle */ + return ECORE_CONFIG_ERR_FAIL; + e->flags = e->flags & ~PF_MODIFIED; + } + + return ret; +} + +/** + * Sets the indicated property if it has not already been set or loaded. + * @param key The property key. + * @param val Default value of the key. + * @param lo Lowest valid value for the key. + * @param hi Highest valid value for the key. + * @param step Used by integer and float values. + * @return ECORE_CONFIG_ERR_SUCC if there are no errors. + * @note The lo, hi and step parameters are only used when storing integer and + * float properties. + */ +int +ecore_config_default(const char *key, char *val, float lo, float hi, float step) +{ + int ret, type; + Ecore_Config_Prop *e; + + type = ecore_config_guess_type(key, val); + ret = ecore_config_default_typed(key, val, type); + e = ecore_config_get(key); + if (e) + { + if (type == PT_INT) + { + e->step = step; + e->flags |= PF_BOUNDS; + e->lo = lo; + e->hi = hi; + ecore_config_bound(e); + } + else if (type == PT_FLT) + { + e->step = (int)(step * ECORE_CONFIG_FLOAT_PRECISION); + e->flags |= PF_BOUNDS; + e->lo = (int)(lo * ECORE_CONFIG_FLOAT_PRECISION); + e->hi = (int)(hi * ECORE_CONFIG_FLOAT_PRECISION); + ecore_config_bound(e); + } + } + + return ret; +} + +/** + * Sets the indicated property to the given integer if the property has not yet + * been set. + * @param key The property key. + * @param val Integer to set the value to. + * @return ECORE_CONFIG_ERR_SUCC if there are no problems. + */ +int +ecore_config_default_int(const char *key, int val) +{ + return ecore_config_default_typed(key, (void *)&val, PT_INT); +} + +/** + * Sets the indicated property to the given integer if the property has not yet + * been set. + * + * The bounds and step values are set regardless. + * + * @param key The property key. + * @param val Integer to set the property to. + * @param low Lowest valid integer value for the property. + * @param high Highest valid integer value for the property. + * @param step Increment value for the property. + * @return ECORE_CONFIG_ERR_SUCC if there were no problems. + */ +int +ecore_config_default_int_bound(const char *key, int val, int low, int high, + int step) +{ + Ecore_Config_Prop *e; + int ret; + + ret = ecore_config_default_typed(key, (void *)&val, PT_INT); + e = ecore_config_get(key); + if (e) + { + e->step = step; + e->flags |= PF_BOUNDS; + e->lo = low; + e->hi = high; + ecore_config_bound(e); + } + + return ret; +} + +/** + * Sets the indicated property to the given string if the property has not yet + * been set. + * @param key The property key. + * @param val String to set the property to. + * @return ECORE_CONFIG_ERR_SUCC if there were no problems. + */ +int +ecore_config_default_string(const char *key, char *val) +{ + return ecore_config_default_typed(key, (void *)val, PT_STR); +} + +/** + * Sets the indicated property to the given float if the property has not yet + * been set. + * @param key The property key. + * @param val Float to set the property to. + * @return ECORE_CONFIG_ERR_SUCC if there were no problems. + */ +int +ecore_config_default_float(const char *key, float val) +{ + return ecore_config_default_typed(key, (void *)&val, PT_FLT); +} + +/** + * Sets the indicated property to the given float if the property has not yet + * been set. + * + * The bounds and step values are set regardless. + * + * @param key The property key. + * @param val Float to set the property to. + * @param low Lowest valid integer value for the property. + * @param high Highest valid float value for the property. + * @param step Increment value for the property. + * @return ECORE_CONFIG_ERR_SUCC if there were no problems. + */ +int +ecore_config_default_float_bound(const char *key, float val, float low, + float high, float step) +{ + Ecore_Config_Prop *e; + int ret; + + ret = ecore_config_default_typed(key, (void *)&val, PT_FLT); + e = ecore_config_get(key); + if (e) + { + e->step = (int)(step * ECORE_CONFIG_FLOAT_PRECISION); + e->flags |= PF_BOUNDS; + e->lo = (int)(low * ECORE_CONFIG_FLOAT_PRECISION); + e->hi = (int)(high * ECORE_CONFIG_FLOAT_PRECISION); + ecore_config_bound(e); + } + + return ret; +} + +/** + * 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. + * @return ECORE_CONFIG_ERR_SUCC if there are no problems. + */ +int +ecore_config_default_rgb(const char *key, char *val) +{ + return ecore_config_default_typed(key, (void *)val, PT_RGB); +} + +/** + * Sets the indicated property to a theme name if the property has not yet + * been set. + * @param key The property key. + * @param val String giving the name of the theme. + * @return ECORE_CONFIG_ERR_SUCC if the property is set successfully. + */ +int +ecore_config_default_theme(const char *key, char *val) +{ + return ecore_config_default_typed(key, (void *)val, PT_THM); +} + +/** + * Adds a callback function to the list of functions called when a property + * changes. + * @param name Name of the callback. + * @param key The key of the property to listen to. + * @param listener Listener callback function. + * @param tag Tag to pass to the callback when it is called. + * @param data Data to pass to the callback when it is called. + * @return ECORE_CONFIG_ERR_SUCC if successful in setting up the callback. + */ +int +ecore_config_listen(const char *name, const char *key, + Ecore_Config_Listener listener, int tag, void *data) +{ + Ecore_Config_Prop *e; + Ecore_Config_Listener_List *l; + + if (!key) + return ECORE_CONFIG_ERR_NODATA; + + if (!(e = ecore_config_get(key))) + { + int ret = ecore_config_add(key, ""); + + if (ret != ECORE_CONFIG_ERR_SUCC) + { + E(0, "ecore_config_listen: ecore_config_add(\"%s\") failed: %d\n", + key, ret); + return ret; + } + if (!(e = ecore_config_get(key))) + { + E(0, "ecore_config_listen: list of properties corrupted!?\n"); + return ECORE_CONFIG_ERR_FAIL; + } + } + + for (l = e->listeners; l; l = l->next) + if (!strcmp(l->name, name) || (l->listener == listener)) + { + E(1, + "ecore_config_listen: %s is already listening for changes of %s in %s...\n", + name, key, t->identifier ? t->identifier : ""); + return ECORE_CONFIG_ERR_IGNORED; + } + + if (!(l = malloc(sizeof(Ecore_Config_Listener_List)))) + return ECORE_CONFIG_ERR_OOM; + + E(1, "registering listener \"%s\" for \"%s\" (%d)...\n", name, key, e->type); + + memset(l, 0, sizeof(Ecore_Config_Listener_List)); + + l->listener = listener; + l->name = name; + l->data = data; + l->tag = tag; + l->next = e->listeners; + e->listeners = l; + + if (e->type != PT_NIL) /* call right on creation if prop exists and has val */ + listener(key, e->type, tag, data); + + return ECORE_CONFIG_ERR_SUCC; +} + +/** + * Removes a listener callback. + * @param name Name of the callback to remove. + * @param key The property key the callback is listening to. + * @param listener The callback function to remove. + * @return ECORE_CONFIG_ERR_SUCC if successful in removing the callback. + * If no callback matches the given parameters, then + * ECORE_CONFIG_ERR_NOTFOUND is returned. If NULL is passed for NULL, + * ECORE_CONFIG_ERR_NODATA is returned. + */ +int +ecore_config_deaf(const char *name, const char *key, + Ecore_Config_Listener listener) +{ + Ecore_Config_Prop *e; + Ecore_Config_Listener_List *l, *p; + int ret; + + ret = ECORE_CONFIG_ERR_NOTFOUND; + + if (!key) + return ECORE_CONFIG_ERR_NODATA; + + if (!(e = ecore_config_get(key))) + return ECORE_CONFIG_ERR_NOTFOUND; + + for (p = NULL, l = e->listeners; l; p = l, l = l->next) + { + if ((name && !strcmp(l->name, name)) || (l->listener == listener)) + { + ret = ECORE_CONFIG_ERR_SUCC; + if (!p) + e->listeners = e->listeners->next; + else + p->next = l->next; + memset(l, 0, sizeof(Ecore_Config_Listener)); + free(l); + } + } + + return ret; +} + +/** + * Locates the first configuration bundle on the given server. + * @param srv The configuration server. + * @return Pointer to the first configuration bundle. + */ +Ecore_Config_Bundle * +ecore_config_bundle_get_1st(Ecore_Config_Server * srv) +{ /* anchor: global, but read-only */ + return srv->bundles; +} + +/** + * Locates the configuration bundle after the given one. + * @param ns The configuration bundle. + * @return The next configuration bundle. + */ +Ecore_Config_Bundle * +ecore_config_bundle_get_next(Ecore_Config_Bundle * ns) +{ + return ns ? ns->next : NULL; +} + +/** + * Locates a configuration bundle on a configuration server based on its serial + * number. + * @param srv The configuration server. + * @param serial Serial number. + * @return The configuration bundle with the given serial number. + */ +Ecore_Config_Bundle * +ecore_config_bundle_get_by_serial(Ecore_Config_Server * srv, long serial) +{ + Ecore_Config_Bundle *eb; + + eb = srv->bundles; + + if (serial < 0) return NULL; - snprintf(buf,PATH_MAX,"%s/.ecore/%s/.global",p,name); - unlink(buf); + else if (serial == 0) + { + Ecore_Config_Bundle *r = eb; - free(buf); - } - - return do_init(name); + return r; + } + + while (eb) + { + if (eb->serial == serial) + return eb; + eb = eb->next; + } + return NULL; } -Ecore_Config_Server *ecore_config_init_global(char *name) { - char *p; - int global; - char *buf; - global=0; - - if((p=getenv("HOME"))) { /* debug-only ### FIXME */ - if (!(buf=malloc(PATH_MAX*sizeof(char)))) - return NULL; - snprintf(buf,PATH_MAX,"%s/.ecore/%s/.global",p,name); - global = creat(buf, S_IRWXU); - if (global) - close(global); - free(buf); - } - - return do_init(name); +/** + * Gets the Ecore_Config_Bundle with the given identifier from the given + * server. + * @param srv The configuration server. + * @param label The bundle's identifier string. + * @return The bundle with the given identifier string, or NULL if it could not + * be found. + */ +Ecore_Config_Bundle * +ecore_config_bundle_get_by_label(Ecore_Config_Server * srv, const char *label) +{ + Ecore_Config_Bundle *ns; + + ns = srv->bundles; + + while (ns) + { + if (ns->identifier && !strcmp(ns->identifier, label)) + return ns; + ns = ns->next; + } + return NULL; } -int ecore_config_init(char *name) { - char *buf, *p; - Ecore_Config_Prop *sys; - - __ecore_config_app_name = strdup(name); - __ecore_config_server_local = ecore_config_init_local(name); - if (!__ecore_config_server_local) - return ECORE_CONFIG_ERR_FAIL; - - __ecore_config_server_global = ecore_config_init_global(ECORE_CONFIG_GLOBAL_ID); - if (!__ecore_config_server_global) - return ECORE_CONFIG_ERR_FAIL; - - __ecore_config_bundle_local = ecore_config_bundle_new(__ecore_config_server_local, "config"); - - if((p=getenv("HOME"))) { /* debug-only ### FIXME */ - if ((buf=malloc(PATH_MAX*sizeof(char)))) { - snprintf(buf,PATH_MAX,"%s/.e/config.db",p); - if (ecore_config_load_file(buf) != 0) - if (ecore_config_load_file(PACKAGE_DATA_DIR "/system.db") != 0) - return ECORE_CONFIG_ERR_NOFILE; - sys = __ecore_config_bundle_local->data; - while (sys) { - /* unmark it modified - modification will mean it has been overridden */ - sys->flags&=~PF_MODIFIED; - /* mark as system so that examine can hide them */ - sys->flags|=PF_SYSTEM; - sys=sys->next; - } - } - free(buf); - } - - return ECORE_CONFIG_ERR_SUCC; +/** + * Retrieves the bundle's serial number. + * @param ns The configuration bundle. + * @return The bundle's identifier string, or -1 if ns is NULL. + */ +long +ecore_config_bundle_get_serial(Ecore_Config_Bundle * ns) +{ + return ns ? ns->serial : -1; } -int ecore_config_shutdown(void) { - int ret; - ret = _ecore_config_ipc_exit(); - free(__ecore_config_app_name); - free(__ecore_config_bundle_local); - free(__ecore_config_server_local); - free(__ecore_config_server_global); - return ret; +/** + * Retrieves the bundle's identifier. + * @param ns The configuration bundle. + * @return The bundle's identifer string. + */ +char * +ecore_config_bundle_get_label(Ecore_Config_Bundle * ns) +{ + return ns ? ns->identifier : NULL; } +/** + * Creates a new Ecore_Config_Bundle. + * @param srv Config server. + * @param identifier Identifier string for the new bundle. + * @return A pointer to a new Ecore_Config_Bundle. NULL is returned if the + * structure couldn't be allocated. + */ +Ecore_Config_Bundle * +ecore_config_bundle_new(Ecore_Config_Server * srv, const char *identifier) +{ + Ecore_Config_Bundle *t; + static long ss; + + ss = 0; /* bundle unique serial */ + + if ((t = malloc(sizeof(Ecore_Config_Bundle)))) + { + memset(t, 0, sizeof(Ecore_Config_Bundle)); + + t->identifier = (char *)identifier; + t->serial = ++ss; + t->owner = srv->name; + t->next = srv->bundles; + srv->bundles = t; + } + return t; +} + +Ecore_Config_Server * +do_init(char *name) +{ + return _ecore_config_ipc_init(name); +} + +Ecore_Config_Server * +ecore_config_init_local(char *name) +{ + char *p; + char *buf; + + if ((p = getenv("HOME"))) + { /* debug-only ### FIXME */ + if (!(buf = malloc(PATH_MAX * sizeof(char)))) + return NULL; + snprintf(buf, PATH_MAX, "%s/.ecore/%s/.global", p, name); + unlink(buf); + + free(buf); + } + + return do_init(name); +} + +Ecore_Config_Server * +ecore_config_init_global(char *name) +{ + char *p; + int global; + char *buf; + global = 0; + + if ((p = getenv("HOME"))) + { /* debug-only ### FIXME */ + if (!(buf = malloc(PATH_MAX * sizeof(char)))) + return NULL; + snprintf(buf, PATH_MAX, "%s/.ecore/%s/.global", p, name); + global = creat(buf, S_IRWXU); + + if (global) + close(global); + + free(buf); + } + + return do_init(name); +} + +/** + * Initializes the Enlightened Property Library. + * + * This function must be run before any other function in the Enlightened + * Property Library, even if you have run ecore_init(). The name given is + * used to determine the default configuration to load. + * + * @param name Application name + * @return ECORE_CONFIG_ERR_SUCC if the library is successfully set up. + * ECORE_CONFIG_ERR_FAIL otherwise. + * @todo FIXME in here to, er, fix. + */ +int +ecore_config_init(char *name) +{ + char *buf, *p; + Ecore_Config_Prop *sys; + + __ecore_config_app_name = strdup(name); + __ecore_config_server_local = ecore_config_init_local(name); + if (!__ecore_config_server_local) + return ECORE_CONFIG_ERR_FAIL; + + __ecore_config_server_global = + ecore_config_init_global(ECORE_CONFIG_GLOBAL_ID); + if (!__ecore_config_server_global) + return ECORE_CONFIG_ERR_FAIL; + + __ecore_config_bundle_local = + ecore_config_bundle_new(__ecore_config_server_local, "config"); + + if ((p = getenv("HOME"))) + { /* debug-only ### FIXME */ + if ((buf = malloc(PATH_MAX * sizeof(char)))) + { + snprintf(buf, PATH_MAX, "%s/.e/config.db", p); + if (ecore_config_load_file(buf) != 0) + if (ecore_config_load_file(PACKAGE_DATA_DIR "/system.db") != 0) + return ECORE_CONFIG_ERR_NOFILE; + sys = __ecore_config_bundle_local->data; + while (sys) + { + /* unmark it modified - modification will mean it has been overridden */ + sys->flags &= ~PF_MODIFIED; + /* mark as system so that examine can hide them */ + sys->flags |= PF_SYSTEM; + sys = sys->next; + } + } + free(buf); + } + + return ECORE_CONFIG_ERR_SUCC; +} + +/** + * Frees memory and shuts down the library. + * @return ECORE_CONFIG_ERR_IGNORED + */ +int +ecore_config_shutdown(void) +{ + int ret; + + ret = _ecore_config_ipc_exit(); + free(__ecore_config_app_name); + free(__ecore_config_bundle_local); + free(__ecore_config_server_local); + free(__ecore_config_server_global); + return ret; +} diff --git a/legacy/ecore/src/lib/ecore_config/edb.c b/legacy/ecore/src/lib/ecore_config/edb.c index 552e8028e3..b4e1f7f91f 100644 --- a/legacy/ecore/src/lib/ecore_config/edb.c +++ b/legacy/ecore/src/lib/ecore_config/edb.c @@ -10,151 +10,214 @@ #include #include -int ecore_config_load(void) { - char file[PATH_MAX]; - snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name); - return ecore_config_load_file(file); +/** + * Loads the default configuration. + * @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA is + * returned if the file cannot be loaded. + */ +int +ecore_config_load(void) +{ + char file[PATH_MAX]; + + snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"), + __ecore_config_app_name); + return ecore_config_load_file(file); } -int ecore_config_save(void) { - char file[PATH_MAX]; - snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db",getenv("HOME"),__ecore_config_app_name); - return ecore_config_save_file(file); +/** + * Saves the current configuration to the default file. + * @return ECORE_CONFIG_ERR_SUCC is returned on success. + * ECORE_CONFIG_ERR_FAIL is returned if the data cannot be saved. + */ +int +ecore_config_save(void) +{ + char file[PATH_MAX]; + + snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.db", getenv("HOME"), + __ecore_config_app_name); + return ecore_config_save_file(file); } -int ecore_config_load_file(char *file) { - E_DB_File *db; - char **keys; - int key_count; - int x; - int itmp; - float ftmp; - char *type; - char *data; - db=NULL; - type = NULL; - data = NULL; - - db = e_db_open_read(file); - if (!db) { - E(0, "Cannot open database from file %s!\n", file); - return ECORE_CONFIG_ERR_NODATA; - } +/** + * Load the given configuration file to the local configuration. + * @param file Name of the file to load. + * @return ECORE_CONFIG_ERR_SUCC on success. ECORE_CONFIG_ERR_NODATA is + * returned if the file cannot be loaded. + */ +int +ecore_config_load_file(char *file) +{ + E_DB_File *db; + char **keys; + int key_count; + int x; + int itmp; + float ftmp; + char *type; + char *data; - keys = e_db_dump_key_list(file, &key_count); - for (x = 0; x < key_count; x++) { + db = NULL; + type = NULL; + data = NULL; - type = e_db_type_get(db, keys[x]); - if (!type) type = "?"; + db = e_db_open_read(file); + if (!db) + { + E(0, "Cannot open database from file %s!\n", file); + return ECORE_CONFIG_ERR_NODATA; + } - if (!strcmp(type, "int")) { - if (e_db_int_get(db, keys[x], &itmp)) { - ecore_config_set_int(keys[x], itmp); - } else { - E(0, "Could not read key %s!\n", keys[x]); - } - } else if (!strcmp(type, "float")) { - if (e_db_float_get(db, keys[x], &ftmp)) { - ecore_config_set_float(keys[x], ftmp); - } else { - E(0, "Could not read key %s!\n", keys[x]); - } - } else if (!strcmp(type, "str")) { - data = e_db_str_get(db, keys[x]); - if (data) { - itmp = ecore_config_guess_type(keys[x],data); - switch (itmp) { - case PT_RGB: - ecore_config_set_rgb(keys[x],data); - break; - case PT_THM: - ecore_config_set_theme(keys[x],data); - break; - default: - ecore_config_set_string(keys[x],data); - } - free(data); - } else { - E(0, "Could not read key %s!\n", keys[x]); - } - } else { - E(1, "Unexpected type: %s\n", type); - continue; - } - - if (type) free(type); - } - e_db_close(db); - free(keys); - return ECORE_CONFIG_ERR_SUCC; -} -static void -_ecore_config_recurse_mkdir(char *file) { - char *file_ptr; - char *file_tmp; - struct stat status; + keys = e_db_dump_key_list(file, &key_count); + for (x = 0; x < key_count; x++) + { - file_tmp = strdup(file); - file_ptr = file_tmp + strlen(file_tmp); - while (*file_ptr != '/' && file_ptr > file_tmp) - file_ptr--; - *file_ptr = '\0'; + type = e_db_type_get(db, keys[x]); + if (!type) + type = "?"; - if(stat(file_tmp, &status)) { - _ecore_config_recurse_mkdir(file_tmp); - mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR); - } - free(file_tmp); + if (!strcmp(type, "int")) + { + if (e_db_int_get(db, keys[x], &itmp)) + { + ecore_config_set_int(keys[x], itmp); + } + else + { + E(0, "Could not read key %s!\n", keys[x]); + } + } + else if (!strcmp(type, "float")) + { + if (e_db_float_get(db, keys[x], &ftmp)) + { + ecore_config_set_float(keys[x], ftmp); + } + else + { + E(0, "Could not read key %s!\n", keys[x]); + } + } + else if (!strcmp(type, "str")) + { + data = e_db_str_get(db, keys[x]); + if (data) + { + itmp = ecore_config_guess_type(keys[x], data); + switch (itmp) + { + case PT_RGB: + ecore_config_set_rgb(keys[x], data); + break; + case PT_THM: + ecore_config_set_theme(keys[x], data); + break; + default: + ecore_config_set_string(keys[x], data); + } + free(data); + } + else + { + E(0, "Could not read key %s!\n", keys[x]); + } + } + else + { + E(1, "Unexpected type: %s\n", type); + continue; + } + + if (type) + free(type); + } + e_db_close(db); + free(keys); + return ECORE_CONFIG_ERR_SUCC; } -int ecore_config_save_file(char *file) { - Ecore_Config_Prop *next; - E_DB_File *db; - struct stat status; - next=__ecore_config_bundle_local->data; - db = NULL; +static void +_ecore_config_recurse_mkdir(char *file) +{ + char *file_ptr; + char *file_tmp; + struct stat status; - /* if file does not exist check to see if the dirs exist, creating if not */ - if(stat(file, &status)) - _ecore_config_recurse_mkdir(file); + file_tmp = strdup(file); + file_ptr = file_tmp + strlen(file_tmp); + while (*file_ptr != '/' && file_ptr > file_tmp) + file_ptr--; + *file_ptr = '\0'; - db = e_db_open(file); - if (!db) { - E(0, "Cannot open database from file %s!\n", file); - return ECORE_CONFIG_ERR_FAIL; - } - - while (next) { - if (!(next->flags&PF_MODIFIED)) { - next=next->next; - continue; - } - switch (next->type) { - case PT_INT: - e_db_int_set(db, next->key, ecore_config_get_int(next->key)); - break; - case PT_FLT: - e_db_float_set(db, next->key, ecore_config_get_float(next->key)); - break; - case PT_RGB: - e_db_str_set(db, next->key, ecore_config_get_rgbstr(next->key)); - break; - case PT_STR: - e_db_str_set(db, next->key, ecore_config_get_string(next->key)); - break; - case PT_THM: - e_db_str_set(db, next->key, ecore_config_get_theme(next->key)); - break; - case PT_NIL: - /* currently we do nothing for undefined ojects */ - break; - } - - next=next->next; - } - - e_db_close(db); - e_db_flush(); - return ECORE_CONFIG_ERR_SUCC; + if (stat(file_tmp, &status)) + { + _ecore_config_recurse_mkdir(file_tmp); + mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR); + } + free(file_tmp); } +/** + * Saves the local configuration to the given file. + * @param file Name of the file to save to. + * @return ECORE_CONFIG_ERR_SUCC is returned on success. + * ECORE_CONFIG_ERR_FAIL is returned if the data cannot be saved. + */ +int +ecore_config_save_file(char *file) +{ + Ecore_Config_Prop *next; + E_DB_File *db; + struct stat status; + + next = __ecore_config_bundle_local->data; + db = NULL; + + /* if file does not exist check to see if the dirs exist, creating if not */ + if (stat(file, &status)) + _ecore_config_recurse_mkdir(file); + + db = e_db_open(file); + if (!db) + { + E(0, "Cannot open database from file %s!\n", file); + return ECORE_CONFIG_ERR_FAIL; + } + + while (next) + { + if (!(next->flags & PF_MODIFIED)) + { + next = next->next; + continue; + } + switch (next->type) + { + case PT_INT: + e_db_int_set(db, next->key, ecore_config_get_int(next->key)); + break; + case PT_FLT: + e_db_float_set(db, next->key, ecore_config_get_float(next->key)); + break; + case PT_RGB: + e_db_str_set(db, next->key, ecore_config_get_rgbstr(next->key)); + break; + case PT_STR: + e_db_str_set(db, next->key, ecore_config_get_string(next->key)); + break; + case PT_THM: + e_db_str_set(db, next->key, ecore_config_get_theme(next->key)); + break; + case PT_NIL: + /* currently we do nothing for undefined ojects */ + break; + } + + next = next->next; + } + + e_db_close(db); + e_db_flush(); + return ECORE_CONFIG_ERR_SUCC; +} diff --git a/legacy/ecore/src/lib/ecore_config/ipc.h b/legacy/ecore/src/lib/ecore_config/ipc.h index 36ce702955..a93a685a03 100644 --- a/legacy/ecore/src/lib/ecore_config/ipc.h +++ b/legacy/ecore/src/lib/ecore_config/ipc.h @@ -1,33 +1,46 @@ #include #include "Ecore_Config.h" -typedef enum { - IPC_NONE, - IPC_PROP_LIST, - IPC_GLOBAL_PROP_LIST, - IPC_PROP_DESC, - IPC_PROP_GET, - IPC_PROP_SET, +typedef enum +{ + IPC_NONE, + IPC_PROP_LIST, + IPC_GLOBAL_PROP_LIST, + IPC_PROP_DESC, + IPC_PROP_GET, + IPC_PROP_SET, - IPC_BUNDLE_LIST, - IPC_BUNDLE_NEW, - IPC_BUNDLE_LABEL_GET, - IPC_BUNDLE_LABEL_SET, - IPC_BUNDLE_LABEL_FIND, + IPC_BUNDLE_LIST, + IPC_BUNDLE_NEW, + IPC_BUNDLE_LABEL_GET, + IPC_BUNDLE_LABEL_SET, + IPC_BUNDLE_LABEL_FIND, - IPC_LAST + IPC_LAST } Ecore_Config_Ipc_Call; Ecore_Config_Server *_ecore_config_server_convert(void *srv); -char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial); -char *_ecore_config_ipc_prop_desc(Ecore_Config_Server *srv, const long serial,const char *key); -char *_ecore_config_ipc_prop_get(Ecore_Config_Server *srv, const long serial,const char *key); -int _ecore_config_ipc_prop_set(Ecore_Config_Server *srv, const long serial,const char *key,const char *val); - -char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv); -int _ecore_config_ipc_bundle_new(Ecore_Config_Server *srv, const char *); -char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long); -int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long,const char *); -long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *); +char *_ecore_config_ipc_prop_list(Ecore_Config_Server * srv, + const long serial); +char *_ecore_config_ipc_prop_desc(Ecore_Config_Server * srv, + const long serial, + const char *key); +char *_ecore_config_ipc_prop_get(Ecore_Config_Server * srv, + const long serial, + const char *key); +int _ecore_config_ipc_prop_set(Ecore_Config_Server * srv, + const long serial, + const char *key, + const char *val); +char *_ecore_config_ipc_bundle_list(Ecore_Config_Server * srv); +int _ecore_config_ipc_bundle_new(Ecore_Config_Server * srv, + const char *); +char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server * + srv, const long); +int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server * + srv, const long, + const char *); +long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server * + srv, const char *); diff --git a/legacy/ecore/src/lib/ecore_config/ipc_ecore.c b/legacy/ecore/src/lib/ecore_config/ipc_ecore.c index 4dfa13aa81..c56ce259fb 100644 --- a/legacy/ecore/src/lib/ecore_config/ipc_ecore.c +++ b/legacy/ecore/src/lib/ecore_config/ipc_ecore.c @@ -21,307 +21,351 @@ #include "Ecore_Config.h" #include "config.h" +/*****************************************************************************/ + +static int +_ecore_config_ipc_ecore_get_string(char **m, char **r) +{ + char *q; + int l = 0; + + if (!m || !*m) + return ECORE_CONFIG_ERR_NODATA; + if (!r) + return ECORE_CONFIG_ERR_FAIL; + q = *m; + if (*q != 's') + return ECORE_CONFIG_ERR_TYPEMISMATCH; + q++; + l = (*(q++)) << 8; + l += *(q++); + *r = q; + q += l; + *m = q; + E(1, "IPC/eCore: got string-%d \"%s\"\n", l, *r); + return ECORE_CONFIG_ERR_SUCC; +} + +char * +_ecore_config_ipc_global_prop_list(Ecore_Config_Server * srv, const long serial) +{ + E_DB_File *db; + char **keys; + int key_count, x; + estring *s; + int f; + char *buf, *p, *type, *data; + + s = estring_new(8192); + f = 0; + if ((p = getenv("HOME"))) + { /* debug-only ### FIXME */ + if ((buf = malloc(PATH_MAX * sizeof(char)))) + { + snprintf(buf, PATH_MAX, "%s/.e/config.db", p); + db = e_db_open_read(buf); + if (!(db = e_db_open_read(buf))) + if (!(db = e_db_open_read(buf = PACKAGE_DATA_DIR "/system.db"))) + return NULL; + } + } + + keys = e_db_dump_key_list(buf, &key_count); + free(buf); + + for (x = 0; x < key_count; x++) + { + type = e_db_type_get(db, keys[x]); + if (!type) + type = "?"; + + if (!strcmp(type, "int")) + estring_appendf(s, "%s%s: integer", f ? "\n" : "", keys[x]); + else if (!strcmp(type, "float")) + estring_appendf(s, "%s%s: float", f ? "\n" : "", keys[x]); + else if (!strcmp(type, "str")) + { + data = e_db_str_get(db, keys[x]); + if (data) + { + if (ecore_config_guess_type(keys[x], data) == PT_RGB) + estring_appendf(s, "%s%s: colour", f ? "\n" : "", keys[x]); + else + estring_appendf(s, "%s%s: string", f ? "\n" : "", keys[x]); + free(data); + } + else + { + estring_appendf(s, "%s%s: string", f ? "\n" : "", keys[x]); + } + } + else + estring_appendf(s, "%s%s: unknown", f ? "\n" : "", keys[x]); + + if (type) + free(type); + f = 1; + } + e_db_close(db); + free(keys); + + return estring_disown(s); +} /*****************************************************************************/ +static int +_ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data * e, int code, + char *reply) +{ + static int our_ref = 0; + int len = reply ? strlen(reply) + 1 : 0; - -static int _ecore_config_ipc_ecore_get_string(char **m,char **r) { - char *q; - int l=0; - - if(!m||!*m) - return ECORE_CONFIG_ERR_NODATA; - if(!r) - return ECORE_CONFIG_ERR_FAIL; - q=*m; - if(*q!='s') - return ECORE_CONFIG_ERR_TYPEMISMATCH; - q++; - l=(*(q++))<<8; - l+=*(q++); - *r=q; - q+=l; - *m=q; - E(1,"IPC/eCore: got string-%d \"%s\"\n",l,*r); - return ECORE_CONFIG_ERR_SUCC; } - - -char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long serial) { - E_DB_File *db; - char **keys; - int key_count, x; - estring *s; - int f; - char *buf, *p, *type, *data; - - s=estring_new(8192); - f=0; - if((p=getenv("HOME"))) { /* debug-only ### FIXME */ - if ((buf=malloc(PATH_MAX*sizeof(char)))) { - snprintf(buf,PATH_MAX,"%s/.e/config.db",p); - db=e_db_open_read(buf); - if (!(db=e_db_open_read(buf))) - if (!(db=e_db_open_read(buf=PACKAGE_DATA_DIR "/system.db"))) - return NULL; - } - } - - keys = e_db_dump_key_list(buf, &key_count); - free(buf); - - for (x = 0; x < key_count; x++) { - type = e_db_type_get(db, keys[x]); - if (!type) type = "?"; - - if (!strcmp(type, "int")) - estring_appendf(s,"%s%s: integer",f?"\n":"",keys[x]); - else if (!strcmp(type, "float")) - estring_appendf(s,"%s%s: float",f?"\n":"",keys[x]); - else if (!strcmp(type, "str")) { - data = e_db_str_get(db, keys[x]); - if (data) { - if (ecore_config_guess_type(keys[x], data)==PT_RGB) - estring_appendf(s,"%s%s: colour",f?"\n":"",keys[x]); - else - estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]); - free(data); - } else { - estring_appendf(s,"%s%s: string",f?"\n":"",keys[x]); - } - } else - estring_appendf(s,"%s%s: unknown",f?"\n":"",keys[x]); - - if (type) free(type); - f=1; - } - e_db_close(db); - free(keys); - - return estring_disown(s);} - - + our_ref++; + E(1, "IPC/eCore: replying [0,0] %d IRT %d => %d {\"%s\":%d}\n", our_ref, + e->ref, code, reply ? reply : "", len); + return ecore_ipc_client_send(e->client, 0, 0, our_ref, e->ref, code, reply, + len); +} /*****************************************************************************/ +static int +_ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server * server, + Ecore_Ipc_Event_Client_Data * e) +{ + Ecore_Config_Server *srv; + long serial; + int ret; + char *r, *k, *v, *m; + srv = _ecore_config_server_convert(server); + serial = e->minor; + ret = ECORE_CONFIG_ERR_FAIL; + r = NULL; + m = (char *)e->data; + E(1, "IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n", e->major, e->minor, + e->ref, e->size, server); -static int _ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data *e,int code,char *reply) { - static int our_ref=0; - int len=reply?strlen(reply)+1:0; - our_ref++; - E(1,"IPC/eCore: replying [0,0] %d IRT %d => %d {\"%s\":%d}\n",our_ref,e->ref,code,reply?reply:"",len); - return ecore_ipc_client_send(e->client,0,0,our_ref,e->ref,code,reply,len); } - - - + switch (e->major) + { + case IPC_PROP_LIST: + if (srv == __ecore_config_server_global) + r = _ecore_config_ipc_global_prop_list(srv, serial); + else + r = _ecore_config_ipc_prop_list(srv, serial); + break; + case IPC_PROP_DESC: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + r = _ecore_config_ipc_prop_desc(srv, serial, k); + break; + case IPC_PROP_GET: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + r = _ecore_config_ipc_prop_get(srv, serial, k); + break; + case IPC_PROP_SET: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + { + if (_ecore_config_ipc_ecore_get_string(&m, &v) == + ECORE_CONFIG_ERR_SUCC) + return _ecore_config_ipc_ecore_send(e, + _ecore_config_ipc_prop_set + (srv, serial, k, v), NULL); + } + break; + case IPC_BUNDLE_LIST: + r = _ecore_config_ipc_bundle_list(srv); + break; + case IPC_BUNDLE_NEW: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + return _ecore_config_ipc_ecore_send(e, + k ? + _ecore_config_ipc_bundle_new(srv, + k) : + ECORE_CONFIG_ERR_FAIL, NULL); + break; + case IPC_BUNDLE_LABEL_SET: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + return _ecore_config_ipc_ecore_send(e, + k ? + _ecore_config_ipc_bundle_label_set + (srv, serial, + k) : ECORE_CONFIG_ERR_FAIL, + NULL); + break; + case IPC_BUNDLE_LABEL_FIND: + if (_ecore_config_ipc_ecore_get_string(&m, &k) == ECORE_CONFIG_ERR_SUCC) + return _ecore_config_ipc_ecore_send(e, + _ecore_config_ipc_bundle_label_find + (srv, k), NULL); + break; + case IPC_BUNDLE_LABEL_GET: + r = _ecore_config_ipc_bundle_label_get(srv, serial); + break; + } + ret = + _ecore_config_ipc_ecore_send(e, + r ? ECORE_CONFIG_ERR_SUCC : + ECORE_CONFIG_ERR_FAIL, r); + if (r) + { + free(r); + return ret; + } + return ECORE_CONFIG_ERR_NOTFOUND; +} /*****************************************************************************/ -static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore_Ipc_Event_Client_Data *e) { - Ecore_Config_Server *srv; - long serial; - int ret; - char *r,*k,*v,*m; - - srv=_ecore_config_server_convert(server); - serial=e->minor; - ret=ECORE_CONFIG_ERR_FAIL; - r=NULL; - m=(char *)e->data; - E(1,"IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n",e->major,e->minor,e->ref,e->size,server); +static int +_ecore_config_ipc_client_add(void *data, int type, void *event) +{ + Ecore_Ipc_Server **server; + Ecore_Ipc_Event_Client_Data *e; - switch(e->major) { - case IPC_PROP_LIST: - if (srv == __ecore_config_server_global) - r=_ecore_config_ipc_global_prop_list(srv, serial); - else - r=_ecore_config_ipc_prop_list(srv, serial); - break; - case IPC_PROP_DESC: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) - r=_ecore_config_ipc_prop_desc(srv, serial,k); - break; - case IPC_PROP_GET: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) - r=_ecore_config_ipc_prop_get(srv, serial,k); - break; - case IPC_PROP_SET: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) { - if(_ecore_config_ipc_ecore_get_string(&m,&v)==ECORE_CONFIG_ERR_SUCC) - return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_prop_set(srv, serial,k,v),NULL); } - break; + server = (Ecore_Ipc_Server **) data; + e = (Ecore_Ipc_Event_Client_Data *) event; - case IPC_BUNDLE_LIST: - r=_ecore_config_ipc_bundle_list(srv); - break; - case IPC_BUNDLE_NEW: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) - return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_new(srv, k):ECORE_CONFIG_ERR_FAIL,NULL); - break; - case IPC_BUNDLE_LABEL_SET: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) - return _ecore_config_ipc_ecore_send(e,k?_ecore_config_ipc_bundle_label_set(srv, serial,k):ECORE_CONFIG_ERR_FAIL,NULL); - break; - case IPC_BUNDLE_LABEL_FIND: - if(_ecore_config_ipc_ecore_get_string(&m,&k)==ECORE_CONFIG_ERR_SUCC) - return _ecore_config_ipc_ecore_send(e,_ecore_config_ipc_bundle_label_find(srv, k),NULL); - break; - case IPC_BUNDLE_LABEL_GET: - r=_ecore_config_ipc_bundle_label_get(srv, serial); - break; } + if (*server != ecore_ipc_client_server_get(e->client)) + return 1; - ret=_ecore_config_ipc_ecore_send(e,r?ECORE_CONFIG_ERR_SUCC:ECORE_CONFIG_ERR_FAIL,r); - if(r) { - free(r); - return ret; } - return ECORE_CONFIG_ERR_NOTFOUND; } + E(1, "IPC/eCore: Client connected. @ %p\n", server); + return 1; +} +static int +_ecore_config_ipc_client_del(void *data, int type, void *event) +{ + Ecore_Ipc_Server **server; + Ecore_Ipc_Event_Client_Data *e; + server = (Ecore_Ipc_Server **) data; + e = (Ecore_Ipc_Event_Client_Data *) event; + if (*server != ecore_ipc_client_server_get(e->client)) + return 1; + E(1, "IPC/eCore: Client disconnected. @ %p\n", server); + return 1; +} +static int +_ecore_config_ipc_client_sent(void *data, int type, void *event) +{ + Ecore_Ipc_Server **server; + Ecore_Ipc_Event_Client_Data *e; + + server = (Ecore_Ipc_Server **) data; + e = (Ecore_Ipc_Event_Client_Data *) event; + + if (*server != ecore_ipc_client_server_get(e->client)) + return 1; + + _ecore_config_ipc_ecore_handle_request(*server, e); + return 1; +} /*****************************************************************************/ +int +_ecore_config_mod_init(char *pipe_name, void **data) +{ + Ecore_Ipc_Server **server; + struct stat st; + char *p; + int port; + char socket[PATH_MAX]; - -static int _ecore_config_ipc_client_add(void *data,int type,void *event) { - Ecore_Ipc_Server **server; - Ecore_Ipc_Event_Client_Data *e; - server=(Ecore_Ipc_Server **)data; - e=(Ecore_Ipc_Event_Client_Data *)event; - - if (*server != ecore_ipc_client_server_get(e->client)) - return 1; - - E(1,"IPC/eCore: Client connected. @ %p\n",server); - return 1; } - - - -static int _ecore_config_ipc_client_del(void *data, int type, void *event) { - Ecore_Ipc_Server **server; - Ecore_Ipc_Event_Client_Data *e; - server=(Ecore_Ipc_Server **)data; - e=(Ecore_Ipc_Event_Client_Data *)event; - - if (*server != ecore_ipc_client_server_get(e->client)) - return 1; - - E(1,"IPC/eCore: Client disconnected. @ %p\n",server); - return 1; } - - - -static int _ecore_config_ipc_client_sent(void *data,int type,void *event) { - Ecore_Ipc_Server **server; - Ecore_Ipc_Event_Client_Data *e; - server=(Ecore_Ipc_Server **)data; - e=(Ecore_Ipc_Event_Client_Data *)event; - - if (*server != ecore_ipc_client_server_get(e->client)) - return 1; - - _ecore_config_ipc_ecore_handle_request(*server,e); - return 1; } - - - - - - -/*****************************************************************************/ - - - -int _ecore_config_mod_init(char *pipe_name, void **data) { - Ecore_Ipc_Server **server; - struct stat st; - char *p; - int port; - char socket[PATH_MAX]; - - server=(Ecore_Ipc_Server **)data; - port=0; - if(!server) - return ECORE_CONFIG_ERR_FAIL; + server = (Ecore_Ipc_Server **) data; + port = 0; + if (!server) + return ECORE_CONFIG_ERR_FAIL; /* if(*server) return ECORE_CONFIG_ERR_IGNORED; */ - ecore_init(); - if(ecore_ipc_init()<1) - return ECORE_CONFIG_ERR_FAIL; + ecore_init(); + if (ecore_ipc_init() < 1) + return ECORE_CONFIG_ERR_FAIL; - if((p=getenv("HOME"))) { /* debug-only ### FIXME */ - int stale; - stale=1; - while (stale) { - snprintf(socket,PATH_MAX,"%s/.ecore/%s/%d",p,pipe_name,port); + if ((p = getenv("HOME"))) + { /* debug-only ### FIXME */ + int stale; - if(!stat(socket,&st)) { - E(0,"IPC/eCore: pipe \"%s\" already exists!?\n",socket); + stale = 1; + while (stale) + { + snprintf(socket, PATH_MAX, "%s/.ecore/%s/%d", p, pipe_name, port); + + if (!stat(socket, &st)) + { + E(0, "IPC/eCore: pipe \"%s\" already exists!?\n", socket); /* if(unlink(buf)) E(0,"IPC/eCore: could not remove pipe \"%s\": %d\n",buf,errno); }}*/ - port++; - } else { - stale = 0; - } - } - } - *server=ecore_ipc_server_add(ECORE_IPC_LOCAL_USER,pipe_name,port,NULL); - ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _ecore_config_ipc_client_add, server); - ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _ecore_config_ipc_client_del, server); - ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,_ecore_config_ipc_client_sent,server); + port++; + } + else + { + stale = 0; + } + } + } + *server = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, pipe_name, port, NULL); + ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, + _ecore_config_ipc_client_add, server); + ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, + _ecore_config_ipc_client_del, server); + ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, + _ecore_config_ipc_client_sent, server); - if(server) { - E(1,"IPC/eCore: Server is listening on %s.\n", pipe_name); - } + if (server) + { + E(1, "IPC/eCore: Server is listening on %s.\n", pipe_name); + } - return ECORE_CONFIG_ERR_SUCC; } + return ECORE_CONFIG_ERR_SUCC; +} +int +_ecore_config_mod_exit(void **data) +{ + int ret; + Ecore_Ipc_Server **server; + ret = ECORE_CONFIG_ERR_SUCC; + server = (Ecore_Ipc_Server **) data; -int _ecore_config_mod_exit(void **data) { - int ret; - Ecore_Ipc_Server **server; - ret=ECORE_CONFIG_ERR_SUCC; - server=(Ecore_Ipc_Server **)data; - - if(!server) - return ECORE_CONFIG_ERR_FAIL; - - if(*server) { - ecore_ipc_server_del(*server); - *server=NULL; } - - ecore_ipc_shutdown(); - - return ret; } - - + if (!server) + return ECORE_CONFIG_ERR_FAIL; + if (*server) + { + ecore_ipc_server_del(*server); + *server = NULL; + } + ecore_ipc_shutdown(); + return ret; +} /*****************************************************************************/ +int +_ecore_config_mod_poll(void **data) +{ + Ecore_Ipc_Server **server; + server = (Ecore_Ipc_Server **) data; -int _ecore_config_mod_poll(void **data) { - Ecore_Ipc_Server **server; - server=(Ecore_Ipc_Server **)data; - - if(!server) - return ECORE_CONFIG_ERR_FAIL; - - ecore_main_loop_iterate(); - - return ECORE_CONFIG_ERR_SUCC; } + if (!server) + return ECORE_CONFIG_ERR_FAIL; + ecore_main_loop_iterate(); + return ECORE_CONFIG_ERR_SUCC; +} /*****************************************************************************/ diff --git a/legacy/ecore/src/lib/ecore_config/ipc_main.c b/legacy/ecore/src/lib/ecore_config/ipc_main.c index 50e04648ce..3bccef2dc4 100644 --- a/legacy/ecore/src/lib/ecore_config/ipc_main.c +++ b/legacy/ecore/src/lib/ecore_config/ipc_main.c @@ -1,7 +1,6 @@ /* ############## bad */ #define HAVE_EVAS2 - #include "Ecore_Config.h" #include "util.h" #include "ipc.h" @@ -14,320 +13,397 @@ #include #include #include -#include /* malloc(), free() */ +#include /* malloc(), free() */ #ifndef TRUE # define FALSE 0 # define TRUE (!FALSE) #endif -typedef struct _ecore_config_ipc { - void *lib; - void *data; - int (*ipc_init)(char *pipe_name,void **data); - int (*ipc_exit)(void **data); - int (*ipc_poll)(void **data); - struct _ecore_config_ipc *next; +typedef struct _ecore_config_ipc +{ + void *lib; + void *data; + int (*ipc_init) (char *pipe_name, void **data); + int (*ipc_exit) (void **data); + int (*ipc_poll) (void **data); + struct _ecore_config_ipc *next; } Ecore_Config_Ipc; +static Ecore_Config_Ipc *ipc_modules = NULL; +static unsigned long ipc_timer = 0L; +Ecore_Config_Server * +_ecore_config_server_convert(void *srv) +{ + Ecore_Config_Ipc *ipc_tmp; + Ecore_Config_Server *srv_tmp; -static Ecore_Config_Ipc *ipc_modules=NULL; -static unsigned long ipc_timer=0L; + ipc_tmp = ipc_modules; + while (ipc_tmp) + { + srv_tmp = ipc_tmp->data; + while (srv_tmp) + { + if (srv_tmp->server == srv) + return srv_tmp; + srv_tmp = srv_tmp->next; + } + ipc_tmp = ipc_tmp->next; + } - -Ecore_Config_Server *_ecore_config_server_convert(void *srv) { - Ecore_Config_Ipc *ipc_tmp; - Ecore_Config_Server *srv_tmp; - - ipc_tmp = ipc_modules; - while (ipc_tmp) { - srv_tmp = ipc_tmp->data; - while (srv_tmp) { - if (srv_tmp->server == srv) - return srv_tmp; - srv_tmp=srv_tmp->next; - } - ipc_tmp = ipc_tmp->next; - } - - return __ecore_config_server_global; + return __ecore_config_server_global; } /*****************************************************************************/ /* INTERFACE FOR IPC MODULES */ /*****************************/ +char * +_ecore_config_ipc_prop_list(Ecore_Config_Server * srv, const long serial) +{ + Ecore_Config_Bundle *theme; + Ecore_Config_Prop *e; + estring *s; + int f; + theme = ecore_config_bundle_get_by_serial(srv, serial); + e = theme ? theme->data : NULL; + s = estring_new(8192); + f = 0; + while (e) + { + /* ignore system properties in listings, unless they have been overridden */ + if (e->flags & PF_SYSTEM && !(e->flags & PF_MODIFIED)) + { + e = e->next; + continue; + } + estring_appendf(s, "%s%s: %s", f ? "\n" : "", e->key, + ecore_config_get_type(e)); + if (e->flags & PF_BOUNDS) + { + if (e->type == PT_FLT) + estring_appendf(s, ", range %le..%le", + (float)e->lo / ECORE_CONFIG_FLOAT_PRECISION, + (float)e->hi / ECORE_CONFIG_FLOAT_PRECISION); + else + estring_appendf(s, ", range %d..%d", e->lo, e->hi); + } + if (e->type == PT_THM) + estring_appendf(s, ", group %s", e->data ? e->data : "Main"); + f = 1; + e = e->next; + } -char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial) { - Ecore_Config_Bundle *theme; - Ecore_Config_Prop *e; - estring *s; - int f; + return estring_disown(s); +} - theme=ecore_config_bundle_get_by_serial(srv, serial); - e=theme?theme->data:NULL; - s=estring_new(8192); - f=0; - while(e) { - /* ignore system properties in listings, unless they have been overridden */ - if (e->flags&PF_SYSTEM && !(e->flags&PF_MODIFIED)) { - e=e->next; - continue; - } - estring_appendf(s,"%s%s: %s",f?"\n":"",e->key,ecore_config_get_type(e)); - if(e->flags&PF_BOUNDS) { - if (e->type==PT_FLT) - estring_appendf(s,", range %le..%le",(float)e->lo/ECORE_CONFIG_FLOAT_PRECISION,(float)e->hi/ECORE_CONFIG_FLOAT_PRECISION); - else - estring_appendf(s,", range %d..%d",e->lo,e->hi); - } - if(e->type==PT_THM) - estring_appendf(s,", group %s",e->data?e->data:"Main"); - f=1; - e=e->next; } - - return estring_disown(s); } - - - -char *_ecore_config_ipc_prop_desc(Ecore_Config_Server *srv, const long serial,const char *key) { +char * +_ecore_config_ipc_prop_desc(Ecore_Config_Server * srv, const long serial, + const char *key) +{ #ifdef HAVE_EVAS2 - Ecore_Config_Bundle *theme; - Ecore_Config_Prop *e; - theme=ecore_config_bundle_get_by_serial(srv, serial); - e=ecore_config_get(key); + Ecore_Config_Bundle *theme; + Ecore_Config_Prop *e; - if(e) { - estring *s=estring_new(512); - estring_appendf(s,"%s: %s",e->key,ecore_config_get_type(e)); - if(e->flags&PF_BOUNDS) - estring_appendf(s,", range %d..%d",e->lo,e->hi); - return estring_disown(s); } + theme = ecore_config_bundle_get_by_serial(srv, serial); + e = ecore_config_get(key); + + if (e) + { + estring *s = estring_new(512); + + estring_appendf(s, "%s: %s", e->key, ecore_config_get_type(e)); + if (e->flags & PF_BOUNDS) + estring_appendf(s, ", range %d..%d", e->lo, e->hi); + return estring_disown(s); + } #endif - return strdup(""); } + return strdup(""); +} - - -char *_ecore_config_ipc_prop_get(Ecore_Config_Server *srv, const long serial,const char *key) { +char * +_ecore_config_ipc_prop_get(Ecore_Config_Server * srv, const long serial, + const char *key) +{ #ifdef HAVE_EVAS2 - char *ret; - Ecore_Config_Bundle *theme; - ret=NULL; - theme=ecore_config_bundle_get_by_serial(srv, serial); - if((ret=ecore_config_get_as_string(/*theme,*/key))) - return ret; + char *ret; + Ecore_Config_Bundle *theme; + + ret = NULL; + theme = ecore_config_bundle_get_by_serial(srv, serial); + if ((ret = ecore_config_get_as_string( /*theme, */ key))) + return ret; #endif - return strdup(""); } + return strdup(""); +} - - -int _ecore_config_ipc_prop_set(Ecore_Config_Server *srv, const long serial,const char *key,const char *val) { +int +_ecore_config_ipc_prop_set(Ecore_Config_Server * srv, const long serial, + const char *key, const char *val) +{ #ifdef HAVE_EVAS2 - int ret; - Ecore_Config_Bundle *theme; - theme=ecore_config_bundle_get_by_serial(srv, serial); - ret=ecore_config_set(key,(char *)val); - E(1,"ipc.prop.set(%s->%s,\"%s\") => %d\n",theme?theme->identifier:"",key,val,ret); - return ret; + int ret; + Ecore_Config_Bundle *theme; + + theme = ecore_config_bundle_get_by_serial(srv, serial); + ret = ecore_config_set(key, (char *)val); + E(1, "ipc.prop.set(%s->%s,\"%s\") => %d\n", theme ? theme->identifier : "", + key, val, ret); + return ret; #else - return ECORE_CONFIG_ERR_NOTSUPP; + return ECORE_CONFIG_ERR_NOTSUPP; #endif } - /*****************************************************************************/ +char * +_ecore_config_ipc_bundle_list(Ecore_Config_Server * srv) +{ + Ecore_Config_Bundle *ns; + estring *s; + int f; -char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv) { - Ecore_Config_Bundle *ns; - estring *s; - int f; + ns = ecore_config_bundle_get_1st(srv); + s = estring_new(8192); + f = 0; + if (!ns) + return strdup(""); - ns=ecore_config_bundle_get_1st(srv); - s=estring_new(8192); - f=0; - if(!ns) - return strdup(""); + while (ns) + { + estring_appendf(s, "%s%d: %s", f ? "\n" : "", + ecore_config_bundle_get_serial(ns), + ecore_config_bundle_get_label(ns)); + f = 1; + ns = ecore_config_bundle_get_next(ns); + } - while(ns) { - estring_appendf(s,"%s%d: %s",f?"\n":"",ecore_config_bundle_get_serial(ns),ecore_config_bundle_get_label(ns)); - f=1; - ns=ecore_config_bundle_get_next(ns); } + return estring_disown(s); +} - return estring_disown(s); } +int +_ecore_config_ipc_bundle_new(Ecore_Config_Server * srv, const char *label) +{ + if (ecore_config_bundle_new(srv, label)) + return ECORE_CONFIG_ERR_SUCC; + return ECORE_CONFIG_ERR_FAIL; +} +char * +_ecore_config_ipc_bundle_label_get(Ecore_Config_Server * srv, const long serial) +{ + Ecore_Config_Bundle *ns; + char *label; + ns = ecore_config_bundle_get_by_serial(srv, serial); + label = ecore_config_bundle_get_label(ns); + return strdup(label ? label : ""); +} -int _ecore_config_ipc_bundle_new(Ecore_Config_Server *srv, const char *label) { - if (ecore_config_bundle_new(srv, label)) - return ECORE_CONFIG_ERR_SUCC; - return ECORE_CONFIG_ERR_FAIL; } +int +_ecore_config_ipc_bundle_label_set(Ecore_Config_Server * srv, const long serial, + const char *label) +{ + Ecore_Config_Bundle *ns; + ns = ecore_config_bundle_get_by_serial(srv, serial); + if (!(ns->identifier = malloc(sizeof(label)))) + return ECORE_CONFIG_ERR_OOM; + memcpy(ns->identifier, label, sizeof(label)); + return ECORE_CONFIG_ERR_SUCC; +} +long +_ecore_config_ipc_bundle_label_find(Ecore_Config_Server * srv, + const char *label) +{ + Ecore_Config_Bundle *ns; -char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long serial) { - Ecore_Config_Bundle *ns; - char *label; - ns=ecore_config_bundle_get_by_serial(srv, serial); - label=ecore_config_bundle_get_label(ns); - return strdup(label?label:""); } + ns = ecore_config_bundle_get_by_label(srv, label); + return ns ? ecore_config_bundle_get_serial(ns) : -1; +} +static int +_ecore_config_ipc_poll(void *data) +{ + Ecore_Config_Ipc *m; + Ecore_Config_Server *s; + m = (Ecore_Config_Ipc *) data; + while (m) + { + s = m->data; + while (s) + { + m->ipc_poll(&s->server); + s = s->next; + } + m = m->next; + } -int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long serial,const char *label) { - Ecore_Config_Bundle *ns; - ns=ecore_config_bundle_get_by_serial(srv, serial); - if (!(ns->identifier=malloc(sizeof(label)))) - return ECORE_CONFIG_ERR_OOM; - memcpy(ns->identifier,label,sizeof(label)); - return ECORE_CONFIG_ERR_SUCC; } + return TRUE; +} +int +_ecore_config_ipc_exit(void) +{ + Ecore_Config_Ipc *m; + Ecore_Config_Server *l; + if (ipc_timer) + timeout_remove(ipc_timer); + while (ipc_modules) + { + m = ipc_modules; + ipc_modules = ipc_modules->next; + l = m->data; + while (l) + { + m->ipc_exit(&l->server); + l = l->next; + } + free(m); + } + return ECORE_CONFIG_ERR_IGNORED; +} -long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *label) { - Ecore_Config_Bundle *ns; - ns=ecore_config_bundle_get_by_label(srv, label); - return ns?ecore_config_bundle_get_serial(ns):-1; } +Ecore_Config_Server * +_ecore_config_ipc_init(char *pipe_name) +{ + char buf[PATH_MAX]; + glob_t globbuf; + int ret; + unsigned int c; + Ecore_Config_Ipc *nm; + Ecore_Config_Server *list; + Ecore_Config_Server *ret_srv; + nm = NULL; + list = NULL; + ret_srv = NULL; + if (nm) + { + list = (Ecore_Config_Server *) nm->data; + while (list) + { + if (!strcmp(list->name, pipe_name)) + return NULL; + list = list->next; + } + } -static int _ecore_config_ipc_poll(void *data) { - Ecore_Config_Ipc *m; - Ecore_Config_Server *s; + list = NULL; - m=(Ecore_Config_Ipc *)data; - while(m) { - s = m->data; - while (s) { - m->ipc_poll(&s->server); - s = s->next; - } - m=m->next; } + if (ipc_modules) + { + nm = ipc_modules; + while (nm) + { + list = malloc(sizeof(Ecore_Config_Server)); + memset(list, 0, sizeof(Ecore_Config_Server)); + if ((ret = + nm->ipc_init(pipe_name, + &list->server)) != ECORE_CONFIG_ERR_SUCC) + { + E(2, + "_ecore_config_ipc_init: failed to register %s, code %d\n", + pipe_name, ret); + break; + } - return TRUE; } + E(2, "_ecore_config_ipc_init: registered \"%s\"...\n", pipe_name); + list->name = strdup(pipe_name); + list->next = nm->data; + nm->data = list; + if (!ret_srv) + ret_srv = list; + nm = nm->next; + } -int _ecore_config_ipc_exit(void) { - Ecore_Config_Ipc *m; - Ecore_Config_Server *l; - - if(ipc_timer) - timeout_remove(ipc_timer); - while(ipc_modules) { - m=ipc_modules; - ipc_modules=ipc_modules->next; - l=m->data; - while(l) { - m->ipc_exit(&l->server); - l=l->next; - } - free(m); } - return ECORE_CONFIG_ERR_IGNORED; } + return ret_srv; + } + if (((ret = + snprintf(buf, PATH_MAX, PACKAGE_LIB_DIR "/ecore_config_ipc_*.so")) < 0) + || (ret >= PATH_MAX)) + return NULL; + glob(buf, 0, NULL, &globbuf); + if (!globbuf.gl_pathc) + return NULL; -Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) { - char buf[PATH_MAX]; - glob_t globbuf; - int ret; - unsigned int c; - Ecore_Config_Ipc *nm; - Ecore_Config_Server *list; - Ecore_Config_Server *ret_srv; - nm=NULL; - list=NULL; - ret_srv=NULL; + for (c = 0; c < globbuf.gl_pathc; c++) + { + if (!(nm = malloc(sizeof(Ecore_Config_Ipc)))) + { + ret = ECORE_CONFIG_ERR_OOM; + goto done; + } + memset(nm, 0, sizeof(Ecore_Config_Ipc)); - if (nm) { - list=(Ecore_Config_Server *)nm->data; - while (list) { - if (!strcmp(list->name, pipe_name)) - return NULL; - - list = list->next; - } - } - - list=NULL; - - if (ipc_modules) { - nm = ipc_modules; - while (nm) { - list=malloc(sizeof(Ecore_Config_Server)); - memset(list, 0, sizeof(Ecore_Config_Server)); - if((ret=nm->ipc_init(pipe_name,&list->server))!=ECORE_CONFIG_ERR_SUCC) { - E(2,"_ecore_config_ipc_init: failed to register %s, code %d\n", pipe_name, ret); - break; - } - - E(2,"_ecore_config_ipc_init: registered \"%s\"...\n",pipe_name); - - list->name=strdup(pipe_name); - list->next=nm->data; - - nm->data=list; - if (!ret_srv) ret_srv=list; - nm = nm->next; - } - - return ret_srv; - } - - if(((ret=snprintf(buf,PATH_MAX,PACKAGE_LIB_DIR "/ecore_config_ipc_*.so"))<0)|| - (ret>=PATH_MAX)) - return NULL; - - glob(buf,0,NULL,&globbuf); - if(!globbuf.gl_pathc) - return NULL; - - for(c=0;clib, - "!_ecore_config_mod_init !_ecore_config_mod_exit !_ecore_config_mod_poll", - &nm->ipc_init,&nm->ipc_exit,&nm->ipc_poll); - if(ret==ECORE_CONFIG_ERR_NODATA) - E(0,"_ecore_config_ipc_init: could not load \"%s\": %s...\n",globbuf.gl_pathv[c],dlerror()); - else if(ret==ECORE_CONFIG_ERR_SUCC) { - list=malloc(sizeof(Ecore_Config_Server)); + E(1, "_ecore_config_ipc_init: checking \"%s\"...\n", + globbuf.gl_pathv[c]); + ret = + dlmulti("IPC-plugin", globbuf.gl_pathv[c], RTLD_NOW, &nm->lib, + "!_ecore_config_mod_init !_ecore_config_mod_exit !_ecore_config_mod_poll", + &nm->ipc_init, &nm->ipc_exit, &nm->ipc_poll); + if (ret == ECORE_CONFIG_ERR_NODATA) + E(0, "_ecore_config_ipc_init: could not load \"%s\": %s...\n", + globbuf.gl_pathv[c], dlerror()); + else if (ret == ECORE_CONFIG_ERR_SUCC) + { + list = malloc(sizeof(Ecore_Config_Server)); /* memcpy(list, 0, sizeof(Ecore_Config_Server));*/ - if((ret=nm->ipc_init(pipe_name,&list->server))!=ECORE_CONFIG_ERR_SUCC) - E(0,"_ecore_config_ipc_init: could not initialize \"%s\": %d\n",globbuf.gl_pathv[c],ret); - else { - char *p=globbuf.gl_pathv[c]; - if(DEBUG!=0) { - char *q=strrchr(p,DIR_DELIMITER); - if(q) - p=++q; } - E(0,"_ecore_config_ipc_init: adding \"%s\"...\n",p); - E(2,"_ecore_config_ipc_init: registered \"%s\"...\n",pipe_name); - - list->name=strdup(pipe_name); - list->next=nm->data; - nm->data=list; - if (!ret_srv) ret_srv=list; + if ((ret = + nm->ipc_init(pipe_name, + &list->server)) != ECORE_CONFIG_ERR_SUCC) + E(0, + "_ecore_config_ipc_init: could not initialize \"%s\": %d\n", + globbuf.gl_pathv[c], ret); + else + { + char *p = globbuf.gl_pathv[c]; - nm->next=ipc_modules; - ipc_modules=nm; }} - if(ret!=ECORE_CONFIG_ERR_SUCC) - free(nm); } + if (DEBUG != 0) + { + char *q = strrchr(p, DIR_DELIMITER); + + if (q) + p = ++q; + } + E(0, "_ecore_config_ipc_init: adding \"%s\"...\n", p); + E(2, "_ecore_config_ipc_init: registered \"%s\"...\n", + pipe_name); + + list->name = strdup(pipe_name); + list->next = nm->data; + nm->data = list; + if (!ret_srv) + ret_srv = list; + + nm->next = ipc_modules; + ipc_modules = nm; + } + } + if (ret != ECORE_CONFIG_ERR_SUCC) + free(nm); + } done: - globfree(&globbuf); - - if(ipc_modules) { - ipc_timer=timeout_add(100,_ecore_config_ipc_poll,ipc_modules); } - return ret_srv; } - + globfree(&globbuf); + if (ipc_modules) + { + ipc_timer = timeout_add(100, _ecore_config_ipc_poll, ipc_modules); + } + return ret_srv; +} /*****************************************************************************/ diff --git a/legacy/ecore/src/lib/ecore_config/util.c b/legacy/ecore/src/lib/ecore_config/util.c index ebe362f0e4..7f7c1e1203 100644 --- a/legacy/ecore/src/lib/ecore_config/util.c +++ b/legacy/ecore/src/lib/ecore_config/util.c @@ -3,14 +3,14 @@ /*#include */ #include -#include /* gimetimeofday() */ -#include /* NULL */ -#include /* malloc(), free() */ -#include /* str...() */ -#include /* isspace() */ +#include /* gimetimeofday() */ +#include /* NULL */ +#include /* malloc(), free() */ +#include /* str...() */ +#include /* isspace() */ -#include /* varargs in dlmulti() */ -#include /* dlopen() and friends for dlmulti() */ +#include /* varargs in dlmulti() */ +#include /* dlopen() and friends for dlmulti() */ /* #ifdef HAVE_GLIB2 */ /* # include */ @@ -21,158 +21,184 @@ #define CHUNKLEN 4096 - /*****************************************************************************/ /* MISC */ /********/ - - -int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...) { +int +dlmulti(char *name, char *file, int flag, void **libr, const char *fmt, ...) +{ #define MAX_SYM_LEN 256 - va_list ap; - void *lib; - int ret=ECORE_CONFIG_ERR_SUCC; - char buf[MAX_SYM_LEN]="\0"; + va_list ap; + void *lib; + int ret = ECORE_CONFIG_ERR_SUCC; + char buf[MAX_SYM_LEN] = "\0"; - if(!libr) - return ECORE_CONFIG_ERR_FAIL; + if (!libr) + return ECORE_CONFIG_ERR_FAIL; - if(!name) - name=file; + if (!name) + name = file; - *libr=NULL; + *libr = NULL; - if((lib=dlopen(file,flag))) { - void **funr,*fun; - char *b,*e; - size_t l; - int required=1; + if ((lib = dlopen(file, flag))) + { + void **funr, *fun; + char *b, *e; + size_t l; + int required = 1; - va_start(ap,fmt); - while(*fmt) { - switch(*fmt) { - case '?': - required=0; - fmt++; - break; + va_start(ap, fmt); + while (*fmt) + { + switch (*fmt) + { + case '?': + required = 0; + fmt++; + break; - case '!': - case '.': - required=1; - fmt++; - break; + case '!': + case '.': + required = 1; + fmt++; + break; - case '\t': - case '\n': - case '\r': - case ';': - case ',': - case ' ': - fmt++; - break; + case '\t': + case '\n': + case '\r': + case ';': + case ',': + case ' ': + fmt++; + break; - default: - e=b=(char *)fmt; - while(*e&&(strchr("?!.,; \t\n\r",*e)==NULL)) - e++; + default: + e = b = (char *)fmt; + while (*e && (strchr("?!.,; \t\n\r", *e) == NULL)) + e++; - fmt=e; - if(e==b) - ret=ECORE_CONFIG_ERR_NODATA; - else if((l=(e-b))>=MAX_SYM_LEN) - ret=ECORE_CONFIG_ERR_OOM; - else { - memcpy(buf,b,l); - buf[l]='\0'; - funr=va_arg(ap,void **); - if(!(fun=dlsym(lib,buf))) { - if((ret=required?ECORE_CONFIG_ERR_NOTFOUND:ECORE_CONFIG_ERR_PARTIAL)==ECORE_CONFIG_ERR_NOTFOUND) - E(1,"DLMulti: library/plugin/engine \"%s\" (\"%s\") did not contain required function \"%s\"...\n",name,file,buf); } - E(2,"DLMulti: %p => %p %c\"%s\"\n",fun,funr,required?'!':'?',buf); - if(funr) - *funr=fun; } - required=1; }} + fmt = e; + if (e == b) + ret = ECORE_CONFIG_ERR_NODATA; + else if ((l = (e - b)) >= MAX_SYM_LEN) + ret = ECORE_CONFIG_ERR_OOM; + else + { + memcpy(buf, b, l); + buf[l] = '\0'; + funr = va_arg(ap, void **); - va_end(ap); + if (!(fun = dlsym(lib, buf))) + { + if ((ret = + required ? ECORE_CONFIG_ERR_NOTFOUND : + ECORE_CONFIG_ERR_PARTIAL) == + ECORE_CONFIG_ERR_NOTFOUND) + E(1, + "DLMulti: library/plugin/engine \"%s\" (\"%s\") did not contain required function \"%s\"...\n", + name, file, buf); + } + E(2, "DLMulti: %p => %p %c\"%s\"\n", fun, funr, + required ? '!' : '?', buf); + if (funr) + *funr = fun; + } + required = 1; + } + } - if((ret==ECORE_CONFIG_ERR_SUCC)||(ret==ECORE_CONFIG_ERR_PARTIAL)) - *libr=lib; - else - dlclose(lib); } - else - ret=ECORE_CONFIG_ERR_NODATA; - - return ret; } + va_end(ap); + if ((ret == ECORE_CONFIG_ERR_SUCC) || (ret == ECORE_CONFIG_ERR_PARTIAL)) + *libr = lib; + else + dlclose(lib); + } + else + ret = ECORE_CONFIG_ERR_NODATA; + return ret; +} /*****************************************************************************/ +unsigned long +now(long delay) +{ + static struct timeval tv; + unsigned long r; - -unsigned long now(long delay) { - static struct timeval tv; - unsigned long r; - gettimeofday(&tv,NULL); - r=tv.tv_sec*1000+(((float)tv.tv_usec)/1000.0)+delay; - return r; } - - + gettimeofday(&tv, NULL); + r = tv.tv_sec * 1000 + (((float)tv.tv_usec) / 1000.0) + delay; + return r; +} /*****************************************************************************/ - - -int parse_line(char *in,char **o1,char **o2,char **o3,char **o4) { +int +parse_line(char *in, char **o1, char **o2, char **o3, char **o4) +{ #define PLMAX 16 - int c; - char *p=in; - char *r[PLMAX]; + int c; + char *p = in; + char *r[PLMAX]; - for(c=0;cl)&&(compare(data,a[h],p)>=0)) - h=h-1; - if(l l) && (compare(data, a[h], p) >= 0)) + h = h - 1; + if (l < h) + { + t = a[l]; + a[l] = a[h]; + a[h] = t; + } + } + while (l < h); + t = a[l]; + a[l] = a[hi]; + a[hi] = t; + qsrt(a, data, lo, l - 1, compare); + qsrt(a, data, l + 1, hi, compare); + } +} /*****************************************************************************/ /* TIMERS */ /**********/ - - -unsigned long timeout_add(uint f,int(*fun)(void *),void *data) { +unsigned long +timeout_add(uint f, int (*fun) (void *), void *data) +{ #ifdef HAVE_GLIB2 - return g_timeout_add((guint)f,(GSourceFunc)fun,(gpointer)data); + return g_timeout_add((guint) f, (GSourceFunc) fun, (gpointer) data); #endif - return 0; } + return 0; +} - - -int timeout_remove(unsigned long handle) { +int +timeout_remove(unsigned long handle) +{ #ifdef HAVE_GLIB2 - return g_source_remove(handle)?ECORE_CONFIG_ERR_SUCC:ECORE_CONFIG_ERR_FAIL; + return g_source_remove(handle) ? ECORE_CONFIG_ERR_SUCC : + ECORE_CONFIG_ERR_FAIL; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } - - - - - + return ECORE_CONFIG_ERR_NOTSUPP; +} /*****************************************************************************/ /* HASHES */ /**********/ +int +eslist_free(eslist ** l) +{ + eslist *e, *f; + if (!l) + return ECORE_CONFIG_ERR_NODATA; + for (e = *l; e; e = f) + { + f = e->next; + free(e); + } + *l = NULL; + return ECORE_CONFIG_ERR_SUCC; +} -int eslist_free(eslist **l) { - eslist *e,*f; - if(!l) - return ECORE_CONFIG_ERR_NODATA; - for(e=*l;e;e=f) { - f=e->next; - free(e); } - *l=NULL; - return ECORE_CONFIG_ERR_SUCC; } +int +eslist_next(eslist ** e) +{ + if (!e || !*e) + return ECORE_CONFIG_ERR_NODATA; + *e = (*e)->next; + return ECORE_CONFIG_ERR_SUCC; +} +void * +eslist_payload(eslist ** e) +{ + return (!e || !*e) ? NULL : (*e)->payload; +} +int +eslist_prepend(eslist ** e, void *p) +{ + eslist *f; -int eslist_next(eslist **e) { - if(!e||!*e) - return ECORE_CONFIG_ERR_NODATA; - *e=(*e)->next; - return ECORE_CONFIG_ERR_SUCC; } + if (!e) + return ECORE_CONFIG_ERR_NODATA; + if (!(f = malloc(sizeof(eslist)))) + return ECORE_CONFIG_ERR_OOM; + f->payload = p; + f->next = *e; -void *eslist_payload(eslist **e) { - return (!e||!*e)?NULL:(*e)->payload; } + *e = f; + return ECORE_CONFIG_ERR_SUCC; +} +int +eslist_append(eslist ** e, void *p) +{ + eslist *f; -int eslist_prepend(eslist **e,void *p) { - eslist *f; - - if(!e) - return ECORE_CONFIG_ERR_NODATA; - - if(!(f=malloc(sizeof(eslist)))) - return ECORE_CONFIG_ERR_OOM; - - f->payload=p; - f->next=*e; - - *e=f; - - return ECORE_CONFIG_ERR_SUCC; } - - - -int eslist_append(eslist **e,void *p) { - eslist *f; - - if(!e) - return ECORE_CONFIG_ERR_NODATA; - - if(!(f=malloc(sizeof(eslist)))) - return ECORE_CONFIG_ERR_OOM; - - f->payload=p; - f->next=NULL; - - if(!*e) - *e=f; - else { - eslist *g=*e; - while(g->next) - g=g->next; - g->next=f; } - - return ECORE_CONFIG_ERR_SUCC; } + if (!e) + return ECORE_CONFIG_ERR_NODATA; + if (!(f = malloc(sizeof(eslist)))) + return ECORE_CONFIG_ERR_OOM; + f->payload = p; + f->next = NULL; + if (!*e) + *e = f; + else + { + eslist *g = *e; + while (g->next) + g = g->next; + g->next = f; + } + return ECORE_CONFIG_ERR_SUCC; +} /*****************************************************************************/ /* HASHES */ /**********/ - - -void *hash_table_new(void (*freekey),void (*freeval)) { +void * +hash_table_new(void (*freekey), void (*freeval)) +{ #ifdef HAVE_GLIB2 - return g_hash_table_new_full(g_str_hash,g_str_equal,freekey,freeval); + return g_hash_table_new_full(g_str_hash, g_str_equal, freekey, freeval); #endif - return NULL; } + return NULL; +} - - -void *hash_table_fetch(void *hashtable,char *key) { +void * +hash_table_fetch(void *hashtable, char *key) +{ #ifdef HAVE_GLIB2 - return g_hash_table_lookup(hashtable,key); + return g_hash_table_lookup(hashtable, key); #endif - return NULL; } + return NULL; +} - - -int hash_table_insert(void *hashtable,char *key,void *value) { +int +hash_table_insert(void *hashtable, char *key, void *value) +{ #ifdef HAVE_GLIB2 - g_hash_table_insert(hashtable,key,value); - return ECORE_CONFIG_ERR_SUCC; + g_hash_table_insert(hashtable, key, value); + return ECORE_CONFIG_ERR_SUCC; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } + return ECORE_CONFIG_ERR_NOTSUPP; +} - - -int hash_table_replace(void *hashtable,char *key,void *value) { +int +hash_table_replace(void *hashtable, char *key, void *value) +{ #ifdef HAVE_GLIB2 - g_hash_table_replace(hashtable,key,value); - return ECORE_CONFIG_ERR_SUCC; + g_hash_table_replace(hashtable, key, value); + return ECORE_CONFIG_ERR_SUCC; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } + return ECORE_CONFIG_ERR_NOTSUPP; +} - - -int hash_table_remove(void *hashtable,char *key) { +int +hash_table_remove(void *hashtable, char *key) +{ #ifdef HAVE_GLIB2 - g_hash_table_remove(hashtable,key); - return ECORE_CONFIG_ERR_SUCC; + g_hash_table_remove(hashtable, key); + return ECORE_CONFIG_ERR_SUCC; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } + return ECORE_CONFIG_ERR_NOTSUPP; +} - - -int hash_table_dst(void *hashtable) { +int +hash_table_dst(void *hashtable) +{ #ifdef HAVE_GLIB2 - g_hash_table_destroy(hashtable); - return ECORE_CONFIG_ERR_SUCC; + g_hash_table_destroy(hashtable); + return ECORE_CONFIG_ERR_SUCC; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } + return ECORE_CONFIG_ERR_NOTSUPP; +} - - -int hash_table_walk(void *hashtable,hash_walker fun,void *data) { +int +hash_table_walk(void *hashtable, hash_walker fun, void *data) +{ #ifdef HAVE_GLIB2 - g_hash_table_foreach(hashtable,(GHFunc)fun,data); - return ECORE_CONFIG_ERR_SUCC; + g_hash_table_foreach(hashtable, (GHFunc) fun, data); + return ECORE_CONFIG_ERR_SUCC; #endif - return ECORE_CONFIG_ERR_NOTSUPP; } - - - - - + return ECORE_CONFIG_ERR_NOTSUPP; +} /*****************************************************************************/ /* STRINGS */ /***********/ +estring * +estring_new(int size) +{ + estring *e = malloc(sizeof(estring)); + if (e) + { + memset(e, 0, sizeof(estring)); + if ((size > 0) && (e->str = malloc(size))) + e->alloc = size; + } + return e; +} -estring *estring_new(int size) { - estring *e=malloc(sizeof(estring)); - if(e) { - memset(e,0,sizeof(estring)); - if((size>0)&&(e->str=malloc(size))) - e->alloc=size; } - return e; } +estring * +estring_dst(estring * e) +{ + if (e) + { + if (e->str) + free(e->str); + free(e); + } + return NULL; +} -estring *estring_dst(estring *e) { - if(e) { - if(e->str) - free(e->str); - free(e); } - return NULL; } +char * +estring_disown(estring * e) +{ + if (e) + { + char *r = e->str; -char *estring_disown(estring *e) { - if(e) { - char *r=e->str; - free(e); - return r; } - return NULL; } + free(e); + return r; + } + return NULL; +} -char *estring_free(estring *e,int release_payload) { /* glib compat */ - if(release_payload) { - estring_dst(e); - return NULL; } - return estring_disown(e); } +char * +estring_free(estring * e, int release_payload) +{ /* glib compat */ + if (release_payload) + { + estring_dst(e); + return NULL; + } + return estring_disown(e); +} -int estring_truncate(estring *e,int size) { - if(!e||(size<0)) - return ECORE_CONFIG_ERR_FAIL; - if(e->used<=size) - return e->used; - e->str[size]='\0'; - e->used=size; - return size; } +int +estring_truncate(estring * e, int size) +{ + if (!e || (size < 0)) + return ECORE_CONFIG_ERR_FAIL; + if (e->used <= size) + return e->used; + e->str[size] = '\0'; + e->used = size; + return size; +} -int estring_printf(estring *e,char *fmt, ...) { - int need; - va_list ap; - char *p; +int +estring_printf(estring * e, char *fmt, ...) +{ + int need; + va_list ap; + char *p; - if(!e) - return ECORE_CONFIG_ERR_FAIL; + if (!e) + return ECORE_CONFIG_ERR_FAIL; - if(!(e->str)) { - if(!(e->str=(char*)malloc(e->alloc=512))) - return ECORE_CONFIG_ERR_OOM; } + if (!(e->str)) + { + if (!(e->str = (char *)malloc(e->alloc = 512))) + return ECORE_CONFIG_ERR_OOM; + } -retry: - va_start(ap,fmt); - need=vsnprintf(e->str,e->alloc,fmt,ap); - va_end(ap); + retry: + va_start(ap, fmt); + need = vsnprintf(e->str, e->alloc, fmt, ap); + va_end(ap); - if((need>=e->alloc)||(need<0)) { - if(need<0) - need=2*e->alloc; - else - need++; - if(!(p=(char*)realloc(e->str,need))) { - free(e->str); - e->alloc=e->used=0; - return ECORE_CONFIG_ERR_OOM; } - e->alloc=need; - e->str=p; - goto retry; } + if ((need >= e->alloc) || (need < 0)) + { + if (need < 0) + need = 2 * e->alloc; + else + need++; + if (!(p = (char *)realloc(e->str, need))) + { + free(e->str); + e->alloc = e->used = 0; + return ECORE_CONFIG_ERR_OOM; + } + e->alloc = need; + e->str = p; + goto retry; + } - return e->used=need; } + return e->used = need; +} -int estring_appendf(estring *e,char *fmt, ...) { - int need; - va_list ap; - char *p; +int +estring_appendf(estring * e, char *fmt, ...) +{ + int need; + va_list ap; + char *p; - if(!e) - return ECORE_CONFIG_ERR_FAIL; + if (!e) + return ECORE_CONFIG_ERR_FAIL; - if(!e->str) { - e->used=e->alloc=0; - if(!(e->str=(char*)malloc(e->alloc=512))) - return ECORE_CONFIG_ERR_OOM; } + if (!e->str) + { + e->used = e->alloc = 0; + if (!(e->str = (char *)malloc(e->alloc = 512))) + return ECORE_CONFIG_ERR_OOM; + } -retry: - va_start(ap,fmt); - need=vsnprintf(e->str+e->used,e->alloc-e->used,fmt,ap); - va_end(ap); + retry: + va_start(ap, fmt); + need = vsnprintf(e->str + e->used, e->alloc - e->used, fmt, ap); + va_end(ap); - if((need>=(e->alloc-e->used))||(need<0)) { - if(need<0) - need=2*e->alloc; - else - need++; - need+=e->used; - need+=(CHUNKLEN-(need%CHUNKLEN)); + if ((need >= (e->alloc - e->used)) || (need < 0)) + { + if (need < 0) + need = 2 * e->alloc; + else + need++; + need += e->used; + need += (CHUNKLEN - (need % CHUNKLEN)); - if(!(p=(char*)realloc(e->str,need))) { - free(e->str); - e->alloc=e->used=0; - return ECORE_CONFIG_ERR_OOM; } - e->alloc=need; - e->str=p; - goto retry; } + if (!(p = (char *)realloc(e->str, need))) + { + free(e->str); + e->alloc = e->used = 0; + return ECORE_CONFIG_ERR_OOM; + } + e->alloc = need; + e->str = p; + goto retry; + } - return e->used+=need; } + return e->used += need; +} +int +esprintf(char **result, char *fmt, ...) +{ + int need, have; + va_list ap; + char *n; + if (!result) + return ECORE_CONFIG_ERR_FAIL; -int esprintf(char **result,char *fmt, ...) { - int need,have; - va_list ap; - char *n; + if (!(n = (char *)malloc(have = 512))) + return ECORE_CONFIG_ERR_OOM; - if(!result) - return ECORE_CONFIG_ERR_FAIL; + retry: + va_start(ap, fmt); + need = vsnprintf(n, have, fmt, ap); + va_end(ap); - if(!(n=(char*)malloc(have=512))) - return ECORE_CONFIG_ERR_OOM; + if ((need >= have) || (need < 0)) + { + char *p; -retry: - va_start(ap,fmt); - need=vsnprintf(n,have,fmt,ap); - va_end(ap); - - if((need>=have)||(need<0)) { - char *p; - if(need<0) - need=2*have; - else - need++; - if(!(p=(char*)realloc(n,need))) { - free(n); - return ECORE_CONFIG_ERR_OOM; } - have=need; - n=p; - goto retry; } - - if(*result) - free(*result); - *result=n; - - return need; } + if (need < 0) + need = 2 * have; + else + need++; + if (!(p = (char *)realloc(n, need))) + { + free(n); + return ECORE_CONFIG_ERR_OOM; + } + have = need; + n = p; + goto retry; + } + if (*result) + free(*result); + *result = n; + return need; +} #if 0 -int ejoin(char **result,char *delim, ...) { - int dl,cl,ret=ECORE_CONFIG_ERR_SUCC; - va_list ap; - char *e,*n; +int +ejoin(char **result, char *delim, ...) +{ + int dl, cl, ret = ECORE_CONFIG_ERR_SUCC; + va_list ap; + char *e, *n; - if(!result) - return ECORE_CONFIG_ERR_FAIL; - if(!delim) - delim=""; - dl=strlen(delim); + if (!result) + return ECORE_CONFIG_ERR_FAIL; + if (!delim) + delim = ""; + dl = strlen(delim); - va_start(ap,delim); - cl=-dl; - while((e=va_arg(ap,char *))) - cl+=strlen(e)+dl; - va_end(ap); + va_start(ap, delim); + cl = -dl; + while ((e = va_arg(ap, char *))) + cl += strlen(e) + dl; - if(cl<=0) { - if(!(n=strdup(""))) - ret=ECORE_CONFIG_ERR_OOM; } - else if(!(n=malloc(cl+1))) - ret=ECORE_CONFIG_ERR_OOM; - else { - char *p=n; + va_end(ap); - va_start(ap,delim); - while((e=va_arg(ap,char *))) { - if(dl&&(p!=n)) { - strcpy(p,delim); - p+=dl; } - strcpy(p,e); - p+=strlen(p); } - va_end(ap); } + if (cl <= 0) + { + if (!(n = strdup(""))) + ret = ECORE_CONFIG_ERR_OOM; + } + else if (!(n = malloc(cl + 1))) + ret = ECORE_CONFIG_ERR_OOM; + else + { + char *p = n; - if(*result) - free(*result); - *result=n; + va_start(ap, delim); + while ((e = va_arg(ap, char *))) + { + if (dl && (p != n)) + { + strcpy(p, delim); + p += dl; + } + strcpy(p, e); + p += strlen(p); + } + va_end(ap); + } - return ret; } + if (*result) + free(*result); + *result = n; + return ret; +} +int +ecat(char **result, ...) +{ + int cl, ret = ECORE_CONFIG_ERR_SUCC; + va_list ap; + char *e, *n; -int ecat(char **result, ...) { - int cl,ret=ECORE_CONFIG_ERR_SUCC; - va_list ap; - char *e,*n; + if (!result) + return ECORE_CONFIG_ERR_FAIL; - if(!result) - return ECORE_CONFIG_ERR_FAIL; + va_start(ap, result); + cl = 0; + while ((e = va_arg(ap, char *))) + cl += strlen(e); - va_start(ap,result); - cl=0; - while((e=va_arg(ap,char *))) - cl+=strlen(e); - va_end(ap); + va_end(ap); - if(cl<=0) { - if(!(n=strdup(""))) - ret=ECORE_CONFIG_ERR_OOM; } - else if(!(n=malloc(cl+1))) - ret=ECORE_CONFIG_ERR_OOM; - else { - char *p=n; + if (cl <= 0) + { + if (!(n = strdup(""))) + ret = ECORE_CONFIG_ERR_OOM; + } + else if (!(n = malloc(cl + 1))) + ret = ECORE_CONFIG_ERR_OOM; + else + { + char *p = n; - va_start(ap,result); - while((e=va_arg(ap,char *))) { - strcpy(p,e); - p+=strlen(p); } - va_end(ap); } + va_start(ap, result); + while ((e = va_arg(ap, char *))) + { + strcpy(p, e); + p += strlen(p); + } + va_end(ap); + } - if(*result) - free(*result); - *result=n; + if (*result) + free(*result); + *result = n; - return ret; } + return ret; +} #endif - - - - - /*****************************************************************************/ diff --git a/legacy/ecore/src/lib/ecore_config/util.h b/legacy/ecore/src/lib/ecore_config/util.h index 771993bc47..2555f73ffc 100644 --- a/legacy/ecore/src/lib/ecore_config/util.h +++ b/legacy/ecore/src/lib/ecore_config/util.h @@ -1,58 +1,63 @@ #define TIMER_STOP 0 #define TIMER_CONT 1 -typedef struct _estring { - char *str; - int alloc,used; +typedef struct _estring +{ + char *str; + int alloc, used; } estring; -typedef struct _eslist { - void *payload; - struct _eslist *next; +typedef struct _eslist +{ + void *payload; + struct _eslist *next; } eslist; +int parse_line(char *, char **, char **, char **, char **); +char *unit_size(char *size); -int parse_line(char *,char **,char **,char **,char **); -char *unit_size(char *size); /*unsigned long now(long delay);*/ -void qsrt(void *a[],void *data,int lo,int hi,int (*compare)(const void *,const void *,const void *)); -int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...); +void qsrt(void *a[], void *data, int lo, int hi, + int (*compare) (const void *, const void *, + const void *)); +int dlmulti(char *name, char *file, int flag, void **libr, + const char *fmt, ...); +typedef void (*hash_walker) (char *key, void *value, void *data); +void *hash_table_new(void (*freekey), void (*freeval)); +void *hash_table_fetch(void *hashtable, char *key); +int hash_table_insert(void *hashtable, char *key, void *value); +int hash_table_replace(void *hashtable, char *key, void *value); +int hash_table_remove(void *hashtable, char *key); +int hash_table_dst(void *hashtable); +int hash_table_walk(void *hashtable, hash_walker fun, + void *data); -typedef void (*hash_walker)(char *key,void *value,void *data); +int eslist_free(eslist **); +int eslist_next(eslist **); -void *hash_table_new( void (*freekey),void (*freeval)); -void *hash_table_fetch( void *hashtable,char *key); -int hash_table_insert( void *hashtable,char *key,void *value); -int hash_table_replace(void *hashtable,char *key,void *value); -int hash_table_remove( void *hashtable,char *key); -int hash_table_dst( void *hashtable); -int hash_table_walk( void *hashtable,hash_walker fun,void *data); - -int eslist_free(eslist **); -int eslist_next(eslist **); #define ESLIST_NEXT(e) (e=e->next) -void *eslist_payload(eslist **); -#define ESLIST_PAYLOAD(e) ((e)->payload) -int eslist_prepend(eslist **,void *); -int eslist_append(eslist **,void *); +void *eslist_payload(eslist **); + +#define ESLIST_PAYLOAD(e) ((e)->payload) +int eslist_prepend(eslist **, void *); +int eslist_append(eslist **, void *); + +estring *estring_new(int size); +estring *estring_dst(estring * e); +char *estring_disown(estring * e); +char *estring_free(estring * e, int release_payload); /* glib compat */ +int estring_printf(estring * e, char *fmt, ...); +int estring_appendf(estring * e, char *fmt, ...); +int estring_truncate(estring * e, int size); -estring *estring_new(int size); -estring *estring_dst(estring *e); -char *estring_disown(estring *e); -char *estring_free(estring *e,int release_payload); /* glib compat */ -int estring_printf(estring *e,char *fmt, ...); -int estring_appendf(estring *e,char *fmt, ...); -int estring_truncate(estring *e,int size); #define ESTRING_GET_CSTRING(a) ((a)->str) -int esprintf(char **result,char *fmt, ...); -int ejoin(char **result,char *delim, ...); -int ecat(char **result, ...); - - - -unsigned long timeout_add(unsigned int f,int(*fun)(void *),void *data); -int timeout_remove(unsigned long handle); +int esprintf(char **result, char *fmt, ...); +int ejoin(char **result, char *delim, ...); +int ecat(char **result, ...); +unsigned long timeout_add(unsigned int f, int (*fun) (void *), + void *data); +int timeout_remove(unsigned long handle);