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
This commit is contained in:
Carsten Haitzler 2004-05-08 03:10:45 +00:00
parent a3f6222d01
commit 20df203105
9 changed files with 3104 additions and 2098 deletions

View File

@ -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,75 +37,90 @@
/* 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 {
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 {
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;
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;
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;
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 */
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 */
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 {
typedef struct Ecore_Config_Server
{
void *server;
char *name;
Ecore_Config_Bundle *bundles; /* data anchor */
struct Ecore_Config_Server *next; } Ecore_Config_Server;
struct Ecore_Config_Server *next;
} Ecore_Config_Server;
# ifdef __cplusplus
extern "C" {
extern "C"
{
# endif
/* global ptrs to save passing them through the API */
@ -123,48 +134,64 @@ 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);
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_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_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_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(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_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_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);
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_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);
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);
@ -185,12 +212,12 @@ 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)
@ -202,16 +229,38 @@ 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_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
}

View File

@ -7,78 +7,139 @@
char *__ecore_config_app_description;
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
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_typed(const char *key, void *val, int type, char short_opt, char *long_opt, char *desc) {
return ecore_config_create_typed(key, val, type, 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;
if ((ret=ecore_config_default_typed(key, val, type)) != ECORE_CONFIG_ERR_SUCC)
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)
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)
if ((ret =
ecore_config_set_long_opt(key, long_opt)) != ECORE_CONFIG_ERR_SUCC)
return ret;
ret = ecore_config_describe(key, desc);
return ret;}
return ret;
}
int ecore_config_create_int(const char *key, int val, 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)
{
return
ecore_config_create_typed(key, (void *)&val, PT_INT, short_opt, long_opt, desc);}
ecore_config_create_typed(key, (void *)&val, PT_INT, 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) {
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);
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) {
if (e)
{
e->step = step;
e->flags |= PF_BOUNDS;
e->lo = low;
e->hi = high;
ecore_config_bound(e);
}
return ret;}
return ret;
}
int ecore_config_create_string(const char *key, char *val, 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)
{
return
ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt, desc);}
ecore_config_create_typed(key, (void *)val, PT_STR, short_opt, long_opt,
desc);
}
int ecore_config_create_float(const char *key, float 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)
{
return
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt, desc);}
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) {
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);
ecore_config_create_typed(key, (void *)&val, PT_FLT, short_opt, long_opt,
desc);
e = ecore_config_get(key);
if (e) {
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;}
return ret;
}
int ecore_config_create_rgb(const char *key, char *val, 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)
{
return
ecore_config_create_typed(key, (void *)val, PT_RGB, short_opt, long_opt, desc);}
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) {
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);}
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)
{
@ -108,8 +169,12 @@ ecore_config_evas_font_path_apply (Evas * evas)
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)
{
@ -119,33 +184,41 @@ ecore_config_args_display(void)
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;
if (!__ecore_config_bundle_local)
return;
props = __ecore_config_bundle_local->data;
while (props)
{
if (props->flags&PF_SYSTEM) {
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->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->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) {
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
}
else
ecore_config_set(prop->key, arg);
return ECORE_CONFIG_PARSE_CONTINUE;
}
@ -159,10 +232,12 @@ ecore_config_args_parse(int argc, char **argv)
Ecore_Config_Prop *prop;
nextarg = 1;
while (nextarg < argc) {
while (nextarg < argc)
{
arg = argv[nextarg];
if (*arg != '-') {
if (*arg != '-')
{
printf("Unexpected attribute \"%s\"\n", arg);
nextarg++;
continue;
@ -171,54 +246,76 @@ ecore_config_args_parse(int argc, char **argv)
next_short_opt = 1;
short_opt = *(arg + next_short_opt);
if (short_opt == '-') {
if (short_opt == '-')
{
long_opt = arg + 2;
if (!strcmp(long_opt, "help")) {
if (!strcmp(long_opt, "help"))
{
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
}
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop) {
while (prop)
{
if ((prop->long_opt && !strcmp(long_opt, prop->long_opt))
|| !strcmp(long_opt, prop->key)) {
|| !strcmp(long_opt, prop->key))
{
found = 1;
if ((ret=ecore_config_parse_set(prop, argv[++nextarg], long_opt,'\0'))
!= ECORE_CONFIG_PARSE_CONTINUE);
if ((ret =
ecore_config_parse_set(prop, argv[++nextarg],
long_opt,
'\0')) !=
ECORE_CONFIG_PARSE_CONTINUE);
return ret;
break;
}
prop = prop->next;
}
if (!found) {
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') {
}
else
{
while (short_opt)
{
if (short_opt == 'h')
{
ecore_config_args_display();
return ECORE_CONFIG_PARSE_HELP;
} else {
}
else
{
found = 0;
prop = __ecore_config_bundle_local->data;
while (prop) {
if (short_opt == prop->short_opt) {
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)
if ((ret =
ecore_config_parse_set(prop,
argv[++nextarg],
NULL,
short_opt)) !=
ECORE_CONFIG_PARSE_CONTINUE)
return ret;
break;
}
prop = prop->next;
}
if (!found) {
if (!found)
{
printf("Unrecognised option '%c'\n", short_opt);
printf("Try using -h or --help for more information.\n\n");
printf
("Try using -h or --help for more information.\n\n");
return ECORE_CONFIG_PARSE_EXIT;
}
}
@ -232,7 +329,8 @@ ecore_config_args_parse(int argc, char **argv)
}
void
ecore_config_app_describe(char *description) {
ecore_config_app_describe(char *description)
{
if (__ecore_config_app_description)
free(__ecore_config_app_description);
__ecore_config_app_description = strdup(description);

File diff suppressed because it is too large Load Diff

View File

@ -10,19 +10,45 @@
#include <sys/stat.h>
#include <unistd.h>
int ecore_config_load(void) {
/**
* 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);
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) {
/**
* 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);
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) {
/**
* 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;
@ -31,39 +57,56 @@ int ecore_config_load_file(char *file) {
float ftmp;
char *type;
char *data;
db = NULL;
type = NULL;
data = NULL;
db = e_db_open_read(file);
if (!db) {
if (!db)
{
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_NODATA;
}
keys = e_db_dump_key_list(file, &key_count);
for (x = 0; x < key_count; x++) {
for (x = 0; x < key_count; x++)
{
type = e_db_type_get(db, keys[x]);
if (!type) type = "?";
if (!type)
type = "?";
if (!strcmp(type, "int")) {
if (e_db_int_get(db, keys[x], &itmp)) {
if (!strcmp(type, "int"))
{
if (e_db_int_get(db, keys[x], &itmp))
{
ecore_config_set_int(keys[x], itmp);
} else {
}
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)) {
}
else if (!strcmp(type, "float"))
{
if (e_db_float_get(db, keys[x], &ftmp))
{
ecore_config_set_float(keys[x], ftmp);
} else {
}
else
{
E(0, "Could not read key %s!\n", keys[x]);
}
} else if (!strcmp(type, "str")) {
}
else if (!strcmp(type, "str"))
{
data = e_db_str_get(db, keys[x]);
if (data) {
if (data)
{
itmp = ecore_config_guess_type(keys[x], data);
switch (itmp) {
switch (itmp)
{
case PT_RGB:
ecore_config_set_rgb(keys[x], data);
break;
@ -74,22 +117,29 @@ int ecore_config_load_file(char *file) {
ecore_config_set_string(keys[x], data);
}
free(data);
} else {
}
else
{
E(0, "Could not read key %s!\n", keys[x]);
}
} else {
}
else
{
E(1, "Unexpected type: %s\n", type);
continue;
}
if (type) free(type);
if (type)
free(type);
}
e_db_close(db);
free(keys);
return ECORE_CONFIG_ERR_SUCC;
}
static void
_ecore_config_recurse_mkdir(char *file) {
_ecore_config_recurse_mkdir(char *file)
{
char *file_ptr;
char *file_tmp;
struct stat status;
@ -100,17 +150,27 @@ _ecore_config_recurse_mkdir(char *file) {
file_ptr--;
*file_ptr = '\0';
if(stat(file_tmp, &status)) {
if (stat(file_tmp, &status))
{
_ecore_config_recurse_mkdir(file_tmp);
mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
}
free(file_tmp);
}
int ecore_config_save_file(char *file) {
/**
* 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;
@ -119,17 +179,21 @@ int ecore_config_save_file(char *file) {
_ecore_config_recurse_mkdir(file);
db = e_db_open(file);
if (!db) {
if (!db)
{
E(0, "Cannot open database from file %s!\n", file);
return ECORE_CONFIG_ERR_FAIL;
}
while (next) {
if (!(next->flags&PF_MODIFIED)) {
while (next)
{
if (!(next->flags & PF_MODIFIED))
{
next = next->next;
continue;
}
switch (next->type) {
switch (next->type)
{
case PT_INT:
e_db_int_set(db, next->key, ecore_config_get_int(next->key));
break;
@ -157,4 +221,3 @@ int ecore_config_save_file(char *file) {
e_db_flush();
return ECORE_CONFIG_ERR_SUCC;
}

View File

@ -1,7 +1,8 @@
#include <Ecore_Ipc.h>
#include "Ecore_Config.h"
typedef enum {
typedef enum
{
IPC_NONE,
IPC_PROP_LIST,
IPC_GLOBAL_PROP_LIST,
@ -20,14 +21,26 @@ typedef enum {
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_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 *);
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 *);

View File

@ -21,12 +21,11 @@
#include "Ecore_Config.h"
#include "config.h"
/*****************************************************************************/
static int _ecore_config_ipc_ecore_get_string(char **m,char **r) {
static int
_ecore_config_ipc_ecore_get_string(char **m, char **r)
{
char *q;
int l = 0;
@ -44,10 +43,12 @@ static int _ecore_config_ipc_ecore_get_string(char **m,char **r) {
q += l;
*m = q;
E(1, "IPC/eCore: got string-%d \"%s\"\n", l, *r);
return ECORE_CONFIG_ERR_SUCC; }
return ECORE_CONFIG_ERR_SUCC;
}
char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long serial) {
char *
_ecore_config_ipc_global_prop_list(Ecore_Config_Server * srv, const long serial)
{
E_DB_File *db;
char **keys;
int key_count, x;
@ -57,8 +58,10 @@ char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long se
s = estring_new(8192);
f = 0;
if((p=getenv("HOME"))) { /* debug-only ### FIXME */
if ((buf=malloc(PATH_MAX*sizeof(char)))) {
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)))
@ -70,57 +73,67 @@ char *_ecore_config_ipc_global_prop_list(Ecore_Config_Server *srv, const long se
keys = e_db_dump_key_list(buf, &key_count);
free(buf);
for (x = 0; x < key_count; x++) {
for (x = 0; x < key_count; x++)
{
type = e_db_type_get(db, keys[x]);
if (!type) type = "?";
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")) {
else if (!strcmp(type, "str"))
{
data = e_db_str_get(db, keys[x]);
if (data) {
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 {
}
else
{
estring_appendf(s, "%s%s: string", f ? "\n" : "", keys[x]);
}
} else
}
else
estring_appendf(s, "%s%s: unknown", f ? "\n" : "", keys[x]);
if (type) free(type);
if (type)
free(type);
f = 1;
}
e_db_close(db);
free(keys);
return estring_disown(s);}
return estring_disown(s);
}
/*****************************************************************************/
static int _ecore_config_ipc_ecore_send(Ecore_Ipc_Event_Client_Data *e,int code,char *reply) {
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); }
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) {
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;
@ -131,9 +144,11 @@ static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore
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);
E(1, "IPC/eCore: client sent: [%d,%d] #%d (%d) @ %p\n", e->major, e->minor,
e->ref, e->size, server);
switch(e->major) {
switch (e->major)
{
case IPC_PROP_LIST:
if (srv == __ecore_config_server_global)
r = _ecore_config_ipc_global_prop_list(srv, serial);
@ -149,9 +164,14 @@ static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore
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); }
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:
@ -159,38 +179,52 @@ static int _ecore_config_ipc_ecore_handle_request(Ecore_Ipc_Server *server,Ecore
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);
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);
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);
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; }
break;
}
ret=_ecore_config_ipc_ecore_send(e,r?ECORE_CONFIG_ERR_SUCC:ECORE_CONFIG_ERR_FAIL,r);
if(r) {
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; }
return ret;
}
return ECORE_CONFIG_ERR_NOTFOUND;
}
/*****************************************************************************/
static int _ecore_config_ipc_client_add(void *data,int type,void *event) {
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;
@ -198,13 +232,15 @@ static int _ecore_config_ipc_client_add(void *data,int type,void *event) {
return 1;
E(1, "IPC/eCore: Client connected. @ %p\n", server);
return 1; }
return 1;
}
static int _ecore_config_ipc_client_del(void *data, int type, void *event) {
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;
@ -212,13 +248,15 @@ static int _ecore_config_ipc_client_del(void *data, int type, void *event) {
return 1;
E(1, "IPC/eCore: Client disconnected. @ %p\n", server);
return 1; }
return 1;
}
static int _ecore_config_ipc_client_sent(void *data,int type,void *event) {
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;
@ -226,18 +264,14 @@ static int _ecore_config_ipc_client_sent(void *data,int type,void *event) {
return 1;
_ecore_config_ipc_ecore_handle_request(*server, e);
return 1; }
return 1;
}
/*****************************************************************************/
int _ecore_config_mod_init(char *pipe_name, void **data) {
int
_ecore_config_mod_init(char *pipe_name, void **data)
{
Ecore_Ipc_Server **server;
struct stat st;
char *p;
@ -256,63 +290,74 @@ int _ecore_config_mod_init(char *pipe_name, void **data) {
if (ecore_ipc_init() < 1)
return ECORE_CONFIG_ERR_FAIL;
if((p=getenv("HOME"))) { /* debug-only ### FIXME */
if ((p = getenv("HOME")))
{ /* debug-only ### FIXME */
int stale;
stale = 1;
while (stale) {
while (stale)
{
snprintf(socket, PATH_MAX, "%s/.ecore/%s/%d", p, pipe_name, port);
if(!stat(socket,&st)) {
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 {
}
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);
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) {
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
_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) {
if (*server)
{
ecore_ipc_server_del(*server);
*server=NULL; }
*server = NULL;
}
ecore_ipc_shutdown();
return ret; }
return ret;
}
/*****************************************************************************/
int _ecore_config_mod_poll(void **data) {
int
_ecore_config_mod_poll(void **data)
{
Ecore_Ipc_Server **server;
server = (Ecore_Ipc_Server **) data;
if (!server)
@ -320,8 +365,7 @@ int _ecore_config_mod_poll(void **data) {
ecore_main_loop_iterate();
return ECORE_CONFIG_ERR_SUCC; }
return ECORE_CONFIG_ERR_SUCC;
}
/*****************************************************************************/

View File

@ -1,7 +1,6 @@
/* ############## bad */
#define HAVE_EVAS2
#include "Ecore_Config.h"
#include "util.h"
#include "ipc.h"
@ -21,7 +20,8 @@
# define TRUE (!FALSE)
#endif
typedef struct _ecore_config_ipc {
typedef struct _ecore_config_ipc
{
void *lib;
void *data;
int (*ipc_init) (char *pipe_name, void **data);
@ -30,20 +30,21 @@ typedef struct _ecore_config_ipc {
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_Server *
_ecore_config_server_convert(void *srv)
{
Ecore_Config_Ipc *ipc_tmp;
Ecore_Config_Server *srv_tmp;
ipc_tmp = ipc_modules;
while (ipc_tmp) {
while (ipc_tmp)
{
srv_tmp = ipc_tmp->data;
while (srv_tmp) {
while (srv_tmp)
{
if (srv_tmp->server == srv)
return srv_tmp;
srv_tmp = srv_tmp->next;
@ -58,9 +59,9 @@ Ecore_Config_Server *_ecore_config_server_convert(void *srv) {
/* INTERFACE FOR IPC MODULES */
/*****************************/
char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial) {
char *
_ecore_config_ipc_prop_list(Ecore_Config_Server * srv, const long serial)
{
Ecore_Config_Bundle *theme;
Ecore_Config_Prop *e;
estring *s;
@ -70,77 +71,97 @@ char *_ecore_config_ipc_prop_list(Ecore_Config_Server *srv, const long serial) {
e = theme ? theme->data : NULL;
s = estring_new(8192);
f = 0;
while(e) {
while (e)
{
/* ignore system properties in listings, unless they have been overridden */
if (e->flags&PF_SYSTEM && !(e->flags&PF_MODIFIED)) {
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) {
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);
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; }
e = e->next;
}
return estring_disown(s); }
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);
if(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); }
return estring_disown(s);
}
#endif
return strdup("<undefined>"); }
return strdup("<undefined>");
}
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;
#endif
return strdup("<undefined>"); }
return strdup("<undefined>");
}
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);
E(1, "ipc.prop.set(%s->%s,\"%s\") => %d\n", theme ? theme->identifier : "",
key, val, ret);
return ret;
#else
return ECORE_CONFIG_ERR_NOTSUPP;
#endif
}
/*****************************************************************************/
char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv) {
char *
_ecore_config_ipc_bundle_list(Ecore_Config_Server * srv)
{
Ecore_Config_Bundle *ns;
estring *s;
int f;
@ -151,86 +172,107 @@ char *_ecore_config_ipc_bundle_list(Ecore_Config_Server *srv) {
if (!ns)
return strdup("<no_bundles_created>");
while(ns) {
estring_appendf(s,"%s%d: %s",f?"\n":"",ecore_config_bundle_get_serial(ns),ecore_config_bundle_get_label(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); }
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) {
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; }
return ECORE_CONFIG_ERR_FAIL;
}
char *_ecore_config_ipc_bundle_label_get(Ecore_Config_Server *srv, const long serial) {
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:"<no such bundle>"); }
return strdup(label ? label : "<no such bundle>");
}
int _ecore_config_ipc_bundle_label_set(Ecore_Config_Server *srv, const long serial,const char *label) {
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 ECORE_CONFIG_ERR_SUCC;
}
long _ecore_config_ipc_bundle_label_find(Ecore_Config_Server *srv, const char *label) {
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; }
return ns ? ecore_config_bundle_get_serial(ns) : -1;
}
static int _ecore_config_ipc_poll(void *data) {
static int
_ecore_config_ipc_poll(void *data)
{
Ecore_Config_Ipc *m;
Ecore_Config_Server *s;
m = (Ecore_Config_Ipc *) data;
while(m) {
while (m)
{
s = m->data;
while (s) {
while (s)
{
m->ipc_poll(&s->server);
s = s->next;
}
m=m->next; }
m = m->next;
}
return TRUE; }
return TRUE;
}
int _ecore_config_ipc_exit(void) {
int
_ecore_config_ipc_exit(void)
{
Ecore_Config_Ipc *m;
Ecore_Config_Server *l;
if (ipc_timer)
timeout_remove(ipc_timer);
while(ipc_modules) {
while (ipc_modules)
{
m = ipc_modules;
ipc_modules = ipc_modules->next;
l = m->data;
while(l) {
while (l)
{
m->ipc_exit(&l->server);
l = l->next;
}
free(m); }
return ECORE_CONFIG_ERR_IGNORED; }
free(m);
}
return ECORE_CONFIG_ERR_IGNORED;
}
Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
Ecore_Config_Server *
_ecore_config_ipc_init(char *pipe_name)
{
char buf[PATH_MAX];
glob_t globbuf;
int ret;
@ -238,13 +280,16 @@ Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
Ecore_Config_Ipc *nm;
Ecore_Config_Server *list;
Ecore_Config_Server *ret_srv;
nm = NULL;
list = NULL;
ret_srv = NULL;
if (nm) {
if (nm)
{
list = (Ecore_Config_Server *) nm->data;
while (list) {
while (list)
{
if (!strcmp(list->name, pipe_name))
return NULL;
@ -254,13 +299,20 @@ Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
list = NULL;
if (ipc_modules) {
if (ipc_modules)
{
nm = ipc_modules;
while (nm) {
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);
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;
}
@ -270,64 +322,88 @@ Ecore_Config_Server *_ecore_config_ipc_init(char *pipe_name) {
list->next = nm->data;
nm->data = list;
if (!ret_srv) ret_srv=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))
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;c<globbuf.gl_pathc;c++) {
if(!(nm=malloc(sizeof(Ecore_Config_Ipc)))) {
for (c = 0; c < globbuf.gl_pathc; c++)
{
if (!(nm = malloc(sizeof(Ecore_Config_Ipc))))
{
ret = ECORE_CONFIG_ERR_OOM;
goto done; }
goto done;
}
memset(nm, 0, sizeof(Ecore_Config_Ipc));
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,
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) {
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 {
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) {
if (DEBUG != 0)
{
char *q = strrchr(p, DIR_DELIMITER);
if (q)
p=++q; }
p = ++q;
}
E(0, "_ecore_config_ipc_init: adding \"%s\"...\n", p);
E(2,"_ecore_config_ipc_init: registered \"%s\"...\n",pipe_name);
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_srv)
ret_srv = list;
nm->next = ipc_modules;
ipc_modules=nm; }}
ipc_modules = nm;
}
}
if (ret != ECORE_CONFIG_ERR_SUCC)
free(nm); }
free(nm);
}
done:
globfree(&globbuf);
if(ipc_modules) {
ipc_timer=timeout_add(100,_ecore_config_ipc_poll,ipc_modules); }
return ret_srv; }
if (ipc_modules)
{
ipc_timer = timeout_add(100, _ecore_config_ipc_poll, ipc_modules);
}
return ret_srv;
}
/*****************************************************************************/

View File

@ -21,14 +21,13 @@
#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;
@ -43,15 +42,18 @@ int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...) {
*libr = NULL;
if((lib=dlopen(file,flag))) {
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) {
while (*fmt)
{
switch (*fmt)
{
case '?':
required = 0;
fmt++;
@ -82,49 +84,62 @@ int dlmulti(char *name,char *file,int flag,void **libr,const char *fmt, ...) {
ret = ECORE_CONFIG_ERR_NODATA;
else if ((l = (e - b)) >= MAX_SYM_LEN)
ret = ECORE_CONFIG_ERR_OOM;
else {
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 (!(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; }}
*funr = fun;
}
required = 1;
}
}
va_end(ap);
if ((ret == ECORE_CONFIG_ERR_SUCC) || (ret == ECORE_CONFIG_ERR_PARTIAL))
*libr = lib;
else
dlclose(lib); }
dlclose(lib);
}
else
ret = ECORE_CONFIG_ERR_NODATA;
return ret; }
return ret;
}
/*****************************************************************************/
unsigned long now(long delay) {
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; }
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;
@ -137,42 +152,53 @@ int parse_line(char *in,char **o1,char **o2,char **o3,char **o4) {
if (!in || !*in)
goto pl_end;
do {
do
{
while (isspace(*p))
*(p++) = '\0';
if (!*p || (strchr("#;", *p) && (!p[1] || isspace(p[1]))))
*p = '\0'; /* it ends HERE */
else {
if(*p=='\"') {
else
{
if (*p == '\"')
{
r[c++] = ++p;
while(*p&&(*p!='\"')) {
while (*p && (*p != '\"'))
{
if ((*p == '\\') && p[1])
p += 2;
else
p++; }
p++;
}
if (*p)
*(p++)='\0'; }
else {
*(p++) = '\0';
}
else
{
r[c++] = p;
while (*p && !isspace(*p))
p++; }}
} while(*p);
p++;
}
}
}
while (*p);
pl_end:
if(o1) *o1=r[0];
if(o2) *o2=r[1];
if(o3) *o3=r[2];
if(o4) *o4=r[3];
return c; }
if (o1)
*o1 = r[0];
if (o2)
*o2 = r[1];
if (o3)
*o3 = r[2];
if (o4)
*o4 = r[3];
return c;
}
/*****************************************************************************/
/*char *unit_size(char *size) {
gchar *unit="byte";
long s;
@ -200,96 +226,104 @@ int parse_line(char *in,char **o1,char **o2,char **o3,char **o4) {
/*****************************************************************************/
void qsrt(void *a[],void *data,int lo,int hi,int (*compare)(const void *,const void *,const void *)) {
void
qsrt(void *a[], void *data, int lo, int hi,
int (*compare) (const void *, const void *, const void *))
{
int h, l;
void *p, *t;
if(lo<hi) {
if (lo < hi)
{
l = lo;
h = hi;
p = a[hi];
do {
do
{
while ((l < h) && (compare(data, a[l], p) <= 0))
l = l + 1;
while ((h > l) && (compare(data, a[h], p) >= 0))
h = h - 1;
if(l<h) {
if (l < h)
{
t = a[l];
a[l] = a[h];
a[h]=t; }
} while(l<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); }}
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);
#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) {
int
eslist_free(eslist ** l)
{
eslist *e, *f;
if (!l)
return ECORE_CONFIG_ERR_NODATA;
for(e=*l;e;e=f) {
for (e = *l; e; e = f)
{
f = e->next;
free(e); }
free(e);
}
*l = NULL;
return ECORE_CONFIG_ERR_SUCC; }
return ECORE_CONFIG_ERR_SUCC;
}
int eslist_next(eslist **e) {
int
eslist_next(eslist ** e)
{
if (!e || !*e)
return ECORE_CONFIG_ERR_NODATA;
*e = (*e)->next;
return ECORE_CONFIG_ERR_SUCC; }
return ECORE_CONFIG_ERR_SUCC;
}
void *
eslist_payload(eslist ** e)
{
return (!e || !*e) ? NULL : (*e)->payload;
}
void *eslist_payload(eslist **e) {
return (!e||!*e)?NULL:(*e)->payload; }
int eslist_prepend(eslist **e,void *p) {
int
eslist_prepend(eslist ** e, void *p)
{
eslist *f;
if (!e)
@ -303,11 +337,12 @@ int eslist_prepend(eslist **e,void *p) {
*e = f;
return ECORE_CONFIG_ERR_SUCC; }
return ECORE_CONFIG_ERR_SUCC;
}
int eslist_append(eslist **e,void *p) {
int
eslist_append(eslist ** e, void *p)
{
eslist *f;
if (!e)
@ -321,133 +356,159 @@ int eslist_append(eslist **e,void *p) {
if (!*e)
*e = f;
else {
else
{
eslist *g = *e;
while (g->next)
g = g->next;
g->next=f; }
return ECORE_CONFIG_ERR_SUCC; }
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);
#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);
#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;
#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;
#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;
#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;
#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;
#endif
return ECORE_CONFIG_ERR_NOTSUPP; }
return ECORE_CONFIG_ERR_NOTSUPP;
}
/*****************************************************************************/
/* STRINGS */
/***********/
estring *estring_new(int size) {
estring *
estring_new(int size)
{
estring *e = malloc(sizeof(estring));
if(e) {
if (e)
{
memset(e, 0, sizeof(estring));
if ((size > 0) && (e->str = malloc(size)))
e->alloc=size; }
return e; }
e->alloc = size;
}
return e;
}
estring *estring_dst(estring *e) {
if(e) {
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;
free(e);
return r; }
return NULL; }
}
return NULL;
}
char *estring_free(estring *e,int release_payload) { /* glib compat */
if(release_payload) {
char *
estring_disown(estring * e)
{
if (e)
{
char *r = e->str;
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); }
return NULL;
}
return estring_disown(e);
}
int estring_truncate(estring *e,int 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; }
return size;
}
int estring_printf(estring *e,char *fmt, ...) {
int
estring_printf(estring * e, char *fmt, ...)
{
int need;
va_list ap;
char *p;
@ -455,31 +516,40 @@ int estring_printf(estring *e,char *fmt, ...) {
if (!e)
return ECORE_CONFIG_ERR_FAIL;
if(!(e->str)) {
if (!(e->str))
{
if (!(e->str = (char *)malloc(e->alloc = 512)))
return ECORE_CONFIG_ERR_OOM; }
return ECORE_CONFIG_ERR_OOM;
}
retry:
va_start(ap, fmt);
need = vsnprintf(e->str, e->alloc, fmt, ap);
va_end(ap);
if((need>=e->alloc)||(need<0)) {
if ((need >= e->alloc) || (need < 0))
{
if (need < 0)
need = 2 * e->alloc;
else
need++;
if(!(p=(char*)realloc(e->str,need))) {
if (!(p = (char *)realloc(e->str, need)))
{
free(e->str);
e->alloc = e->used = 0;
return ECORE_CONFIG_ERR_OOM; }
return ECORE_CONFIG_ERR_OOM;
}
e->alloc = need;
e->str = p;
goto retry; }
goto retry;
}
return e->used=need; }
return e->used = need;
}
int estring_appendf(estring *e,char *fmt, ...) {
int
estring_appendf(estring * e, char *fmt, ...)
{
int need;
va_list ap;
char *p;
@ -487,17 +557,20 @@ int estring_appendf(estring *e,char *fmt, ...) {
if (!e)
return ECORE_CONFIG_ERR_FAIL;
if(!e->str) {
if (!e->str)
{
e->used = e->alloc = 0;
if (!(e->str = (char *)malloc(e->alloc = 512)))
return ECORE_CONFIG_ERR_OOM; }
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);
if((need>=(e->alloc-e->used))||(need<0)) {
if ((need >= (e->alloc - e->used)) || (need < 0))
{
if (need < 0)
need = 2 * e->alloc;
else
@ -505,19 +578,23 @@ retry:
need += e->used;
need += (CHUNKLEN - (need % CHUNKLEN));
if(!(p=(char*)realloc(e->str,need))) {
if (!(p = (char *)realloc(e->str, need)))
{
free(e->str);
e->alloc = e->used = 0;
return ECORE_CONFIG_ERR_OOM; }
return ECORE_CONFIG_ERR_OOM;
}
e->alloc = need;
e->str = p;
goto retry; }
goto retry;
}
return e->used+=need; }
return e->used += need;
}
int esprintf(char **result,char *fmt, ...) {
int
esprintf(char **result, char *fmt, ...)
{
int need, have;
va_list ap;
char *n;
@ -533,29 +610,35 @@ retry:
need = vsnprintf(n, have, fmt, ap);
va_end(ap);
if((need>=have)||(need<0)) {
if ((need >= have) || (need < 0))
{
char *p;
if (need < 0)
need = 2 * have;
else
need++;
if(!(p=(char*)realloc(n,need))) {
if (!(p = (char *)realloc(n, need)))
{
free(n);
return ECORE_CONFIG_ERR_OOM; }
return ECORE_CONFIG_ERR_OOM;
}
have = need;
n = p;
goto retry; }
goto retry;
}
if (*result)
free(*result);
*result = n;
return need; }
return need;
}
#if 0
int ejoin(char **result,char *delim, ...) {
int
ejoin(char **result, char *delim, ...)
{
int dl, cl, ret = ECORE_CONFIG_ERR_SUCC;
va_list ap;
char *e, *n;
@ -570,34 +653,44 @@ int ejoin(char **result,char *delim, ...) {
cl = -dl;
while ((e = va_arg(ap, char *)))
cl += strlen(e) + dl;
va_end(ap);
if(cl<=0) {
if (cl <= 0)
{
if (!(n = strdup("")))
ret=ECORE_CONFIG_ERR_OOM; }
ret = ECORE_CONFIG_ERR_OOM;
}
else if (!(n = malloc(cl + 1)))
ret = ECORE_CONFIG_ERR_OOM;
else {
else
{
char *p = n;
va_start(ap, delim);
while((e=va_arg(ap,char *))) {
if(dl&&(p!=n)) {
while ((e = va_arg(ap, char *)))
{
if (dl && (p != n))
{
strcpy(p, delim);
p+=dl; }
p += dl;
}
strcpy(p, e);
p+=strlen(p); }
va_end(ap); }
p += strlen(p);
}
va_end(ap);
}
if (*result)
free(*result);
*result = n;
return ret; }
return ret;
}
int ecat(char **result, ...) {
int
ecat(char **result, ...)
{
int cl, ret = ECORE_CONFIG_ERR_SUCC;
va_list ap;
char *e, *n;
@ -609,32 +702,35 @@ int ecat(char **result, ...) {
cl = 0;
while ((e = va_arg(ap, char *)))
cl += strlen(e);
va_end(ap);
if(cl<=0) {
if (cl <= 0)
{
if (!(n = strdup("")))
ret=ECORE_CONFIG_ERR_OOM; }
ret = ECORE_CONFIG_ERR_OOM;
}
else if (!(n = malloc(cl + 1)))
ret = ECORE_CONFIG_ERR_OOM;
else {
else
{
char *p = n;
va_start(ap, result);
while((e=va_arg(ap,char *))) {
while ((e = va_arg(ap, char *)))
{
strcpy(p, e);
p+=strlen(p); }
va_end(ap); }
p += strlen(p);
}
va_end(ap);
}
if (*result)
free(*result);
*result = n;
return ret; }
return ret;
}
#endif
/*****************************************************************************/

View File

@ -1,24 +1,27 @@
#define TIMER_STOP 0
#define TIMER_CONT 1
typedef struct _estring {
typedef struct _estring
{
char *str;
int alloc, used;
} estring;
typedef struct _eslist {
typedef struct _eslist
{
void *payload;
struct _eslist *next;
} eslist;
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);
@ -28,12 +31,15 @@ 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 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 *);
@ -45,14 +51,13 @@ 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);
unsigned long timeout_add(unsigned int f, int (*fun) (void *),
void *data);
int timeout_remove(unsigned long handle);