2003-12-05 08:57:32 -08:00
|
|
|
#include "Ecore_Config.h"
|
2004-04-11 09:08:14 -07:00
|
|
|
#include "config.h"
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2004-01-18 01:29:39 -08:00
|
|
|
#include <fcntl.h>
|
2003-12-05 08:57:32 -08:00
|
|
|
#include <limits.h>
|
2004-01-18 01:29:39 -08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <util.h>
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
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;
|
2004-01-22 20:01:40 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Server *_ecore_config_ipc_init(char *name);
|
|
|
|
int _ecore_config_ipc_exit(void);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
static char *_ecore_config_type[]={ "undefined", "integer", "float", "string", "colour", "theme" };
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
Ecore_Config_Prop *ecore_config_dst(Ecore_Config_Prop *e) {
|
|
|
|
Ecore_Config_Bundle *t;
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *p,*c;
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Listener_List *l;
|
2004-03-01 15:11:28 -08:00
|
|
|
p=NULL;
|
|
|
|
c=e;
|
|
|
|
t = __ecore_config_bundle_local;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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; }}
|
|
|
|
|
|
|
|
while(e->listeners) {
|
|
|
|
l=e->listeners;
|
|
|
|
e->listeners=e->listeners->next;
|
|
|
|
free(l); }
|
|
|
|
|
|
|
|
if(e->key)
|
|
|
|
free(e->key);
|
|
|
|
if(e->ptr&&(e->type==PT_STR))
|
|
|
|
free(e->ptr);
|
|
|
|
|
|
|
|
memset(e,0,sizeof(Ecore_Config_Prop));
|
|
|
|
free(e);
|
|
|
|
|
|
|
|
return NULL; }
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
Ecore_Config_Prop *ecore_config_get(Ecore_Config_Bundle *t, const char *key) {
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
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) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return _ecore_config_type[e->type]; }
|
2003-12-05 08:57:32 -08:00
|
|
|
return "not found"; }
|
|
|
|
|
|
|
|
|
2004-03-27 12:59:42 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
void *ecore_config_get_data(const char *key) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2003-12-06 09:24:19 -08:00
|
|
|
return (e?((e->type==PT_STR)?((void *)&e->ptr):((void *)&e->val))
|
2003-12-05 08:57:32 -08:00
|
|
|
:NULL); }
|
|
|
|
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
char *ecore_config_get_string(const char *key) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2003-12-05 08:57:32 -08:00
|
|
|
return (e&&(e->type==PT_STR))?e->ptr:NULL; }
|
|
|
|
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
long ecore_config_get_int(const char *key) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2003-12-05 08:57:32 -08:00
|
|
|
return (e&&((e->type==PT_INT)||(e->type==PT_RGB)))?e->val:0L; }
|
|
|
|
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
float ecore_config_get_float(const char *key) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2004-01-13 13:15:23 -08:00
|
|
|
return (e&&(e->type==PT_FLT))?((float)e->val/ECORE_CONFIG_FLOAT_PRECISION):0.0; }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_get_rgb(const char *key,int *r, int *g, int *b) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
char *ecore_config_get_rgbstr(const char *key) {
|
2004-03-01 15:11:28 -08:00
|
|
|
char *r;
|
|
|
|
r=NULL;
|
2004-01-20 08:19:45 -08:00
|
|
|
esprintf(&r,"#%06x",ecore_config_get_int(key));
|
2003-12-05 08:57:32 -08:00
|
|
|
return r; }
|
2004-01-20 08:19:45 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
char *ecore_config_get_theme(const char *key) {
|
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
|
|
|
return (e&&(e->type==PT_THM))?e->ptr:NULL; }
|
|
|
|
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
char *ecore_config_get_as_string(const char *key) {
|
|
|
|
Ecore_Config_Bundle *t;
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Prop *e;
|
2004-03-01 15:11:28 -08:00
|
|
|
char *r;
|
|
|
|
r=NULL;
|
|
|
|
t = __ecore_config_bundle_local;
|
2003-12-05 08:57:32 -08:00
|
|
|
if(!(e=ecore_config_get(t,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=<nil>",key,type); break;
|
|
|
|
case PT_INT:
|
2004-01-20 08:19:45 -08:00
|
|
|
esprintf(&r,"%s:%s=%ld",key,type,ecore_config_get_int(key)); break;
|
2003-12-05 08:57:32 -08:00
|
|
|
case PT_FLT:
|
2004-01-20 08:19:45 -08:00
|
|
|
esprintf(&r,"%s:%s=%lf",key,type,ecore_config_get_float(key)); break;
|
2003-12-05 08:57:32 -08:00
|
|
|
case PT_STR:
|
2004-01-20 08:19:45 -08:00
|
|
|
esprintf(&r,"%s:%s=\"%s\"",key,type,ecore_config_get_string(key)); break;
|
2003-12-05 08:57:32 -08:00
|
|
|
case PT_RGB:
|
2004-01-20 08:19:45 -08:00
|
|
|
esprintf(&r,"%s:%s=#%06x",key,type,ecore_config_get_int(key)); break;
|
2004-04-22 16:38:19 -07:00
|
|
|
case PT_THM:
|
|
|
|
esprintf(&r,"%s:%s=\"%s\"",key,type,ecore_config_get_theme(key)); break;
|
2003-12-05 08:57:32 -08:00
|
|
|
default:
|
|
|
|
esprintf(&r,"%s:unknown_type",key); break; }}
|
|
|
|
return r; }
|
|
|
|
|
|
|
|
|
|
|
|
static int ecore_config_bound(Ecore_Config_Prop *e) {
|
2004-03-01 15:11:28 -08:00
|
|
|
int ret;
|
2003-12-05 08:57:32 -08:00
|
|
|
long v;
|
2004-03-01 15:11:28 -08:00
|
|
|
ret=ECORE_CONFIG_ERR_SUCC;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
int ecore_config_guess_type(const char *key,char *val) {
|
|
|
|
Ecore_Config_Prop *p;
|
2004-03-01 15:11:28 -08:00
|
|
|
char *l;
|
2003-12-05 08:57:32 -08:00
|
|
|
long v;
|
2004-03-01 15:11:28 -08:00
|
|
|
l=NULL;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
if ((p=ecore_config_get(__ecore_config_bundle_local, key)) && p->type!=PT_NIL)
|
|
|
|
return p->type;
|
|
|
|
|
2003-12-05 08:57:32 -08:00
|
|
|
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) {
|
2004-03-01 15:11:28 -08:00
|
|
|
char *l;
|
|
|
|
long v;
|
2004-04-13 16:36:40 -07:00
|
|
|
int *i;
|
2004-01-13 13:15:23 -08:00
|
|
|
float *f;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
l=NULL;
|
|
|
|
v=0;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-04-13 16:36:40 -07:00
|
|
|
if(!(val))
|
2003-12-05 08:57:32 -08:00
|
|
|
e->ptr=NULL;
|
|
|
|
else {
|
|
|
|
if (type==PT_INT) {
|
2004-04-13 16:36:40 -07:00
|
|
|
i = (int *)val;
|
|
|
|
e->val=(long)*i;
|
2003-12-05 08:57:32 -08:00
|
|
|
e->type=PT_INT;
|
2004-04-22 16:38:19 -07:00
|
|
|
} else if (type==PT_STR || type==PT_THM) {
|
2003-12-05 08:57:32 -08:00
|
|
|
if(!(e->ptr=strdup(val)))
|
|
|
|
return ECORE_CONFIG_ERR_OOM;
|
2004-04-22 16:38:19 -07:00
|
|
|
if (e->type==PT_NIL)
|
|
|
|
e->type=type;
|
2003-12-05 08:57:32 -08:00
|
|
|
} else if (type==PT_RGB) {
|
|
|
|
if (((char *)val)[0]=='#') {
|
|
|
|
if((v=strtol(&((char *)val)[1],&l,16))<0) {
|
|
|
|
v=0;
|
2003-12-06 09:24:19 -08:00
|
|
|
E(0,"ecore_config_val: key \"%s\" -- hexadecimal value less than zero, bound to zero...\n", (char *)val);
|
2003-12-05 08:57:32 -08:00
|
|
|
l=(char *)val;
|
|
|
|
}
|
|
|
|
} else {
|
2003-12-06 09:24:19 -08:00
|
|
|
E(0,"ecore_config_val: key \"%s\" -- value \"%s\" not a valid hexadecimal RGB value?\n",e->key,(char *)val);
|
2003-12-05 08:57:32 -08:00
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
}
|
|
|
|
if(*l)
|
2003-12-06 09:24:19 -08:00
|
|
|
E(0,"ecore_config_val: key \"%s\" -- value \"%s\" not a valid hexadecimal RGB value?\n",e->key,(char *)val);
|
2003-12-05 08:57:32 -08:00
|
|
|
else {
|
|
|
|
e->val=v;
|
|
|
|
e->type=PT_RGB;
|
|
|
|
}
|
|
|
|
} else if (type==PT_FLT) {
|
2004-01-13 13:15:23 -08:00
|
|
|
f = (float *)val;
|
|
|
|
e->val=(long)((*f)*ECORE_CONFIG_FLOAT_PRECISION);
|
|
|
|
e->type=PT_FLT;
|
2004-04-22 16:38:19 -07:00
|
|
|
} else
|
|
|
|
e->type=PT_NIL;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
ecore_config_bound(e);
|
|
|
|
e->flags|=PF_MODIFIED;
|
|
|
|
return ECORE_CONFIG_ERR_SUCC;
|
|
|
|
}
|
2003-12-06 09:24:19 -08:00
|
|
|
return ECORE_CONFIG_ERR_IGNORED;
|
2003-12-05 08:57:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ecore_config_add_typed(Ecore_Config_Bundle *t, const char *key, void* val, int type) {
|
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
|
|
|
|
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(Ecore_Config_Bundle *t,const char *key,char *val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
int type;
|
2004-04-22 16:38:19 -07:00
|
|
|
type=ecore_config_guess_type(key, val);
|
2003-12-05 08:57:32 -08:00
|
|
|
return ecore_config_add_typed(t,key,val,type); }
|
2004-04-22 16:38:19 -07:00
|
|
|
|
|
|
|
void ecore_config_describe(const char *key, char *desc) {
|
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
if ((e=ecore_config_get(__ecore_config_bundle_local, key)))
|
|
|
|
e->description = strdup(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-05 08:57:32 -08:00
|
|
|
int ecore_config_set_typed(Ecore_Config_Bundle *t,const char *key,void *val,int type) {
|
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
Ecore_Config_Listener_List *l;
|
|
|
|
int ret;
|
|
|
|
|
2004-03-27 15:16:48 -08:00
|
|
|
if (!key)
|
2003-12-05 08:57:32 -08:00
|
|
|
return ECORE_CONFIG_ERR_NODATA;
|
2004-03-27 15:16:48 -08:00
|
|
|
if (!t) { /* global prop */
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
|
|
|
if (e)
|
|
|
|
for(l=e->listeners;l;l=l->next)
|
|
|
|
l->listener(e->key,e->type,l->tag,l->data,t);
|
|
|
|
return ECORE_CONFIG_ERR_SUCC;
|
|
|
|
}
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if (!(e=ecore_config_get(t,key)))
|
|
|
|
return ecore_config_add_typed(t,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,t);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
E(0,"ecore_config_set_typed(\"%s\"): ecore_config_val_typed() failed: %d\n",key,ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ecore_config_set(Ecore_Config_Bundle *t,const char *key,char *val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
int type;
|
2004-04-13 16:36:40 -07:00
|
|
|
int tmpi;
|
2004-04-13 15:03:22 -07:00
|
|
|
float tmpf;
|
2004-04-22 16:38:19 -07:00
|
|
|
type=ecore_config_guess_type(key, val);
|
2004-04-13 16:36:40 -07:00
|
|
|
if (type == PT_INT) {
|
|
|
|
tmpi = atoi(val);
|
|
|
|
return ecore_config_set_typed(t,key,(void*) &tmpi,type);
|
|
|
|
} else if (type == PT_FLT) {
|
2004-04-13 15:03:22 -07:00
|
|
|
tmpf = atof(val);
|
|
|
|
return ecore_config_set_typed(t,key,(void*) &tmpf,type);
|
|
|
|
} else
|
2004-03-08 07:44:17 -08:00
|
|
|
return ecore_config_set_typed(t,key,(void*) val,type); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_set_as_string(const char *key,char *val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_set(__ecore_config_bundle_local,key,val); }
|
2004-01-20 08:19:45 -08:00
|
|
|
|
|
|
|
int ecore_config_set_int(const char *key, int val) {
|
2004-04-13 16:36:40 -07:00
|
|
|
return ecore_config_set_typed(__ecore_config_bundle_local,key,(void *)&val,PT_INT); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_set_string(const char *key, char* val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_set_typed(__ecore_config_bundle_local,key,(void *)val,PT_STR); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_set_float(const char *key, float val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_set_typed(__ecore_config_bundle_local,key,(void *)&val,PT_FLT); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_set_rgb(const char *key, char* val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_set_typed(__ecore_config_bundle_local,key,(void *)val,PT_RGB); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
int ecore_config_set_theme(const char *key, char* val) {
|
|
|
|
return ecore_config_set_typed(__ecore_config_bundle_local,key,(void *)val,PT_THM); }
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-13 13:15:23 -08:00
|
|
|
static int ecore_config_default_typed(Ecore_Config_Bundle *t,const char *key,void *val,int type) {
|
2004-03-01 15:11:28 -08:00
|
|
|
int ret;
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Prop *e;
|
2004-03-01 15:11:28 -08:00
|
|
|
ret=ECORE_CONFIG_ERR_SUCC;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if(!(e=ecore_config_get(t,key))) { /* prop doesn't exist yet */
|
2004-01-12 08:08:08 -08:00
|
|
|
if((ret=ecore_config_add_typed(t,key,val,type))!=ECORE_CONFIG_ERR_SUCC) /* try to add it */
|
2003-12-05 08:57:32 -08:00
|
|
|
return ret; /* ...failed */
|
|
|
|
if(!(e=ecore_config_get(t,key))) /* get handle */
|
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
e->flags=e->flags&~PF_MODIFIED; }
|
|
|
|
|
|
|
|
return ret; }
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default(const char *key,char *val,float lo,float hi,float step) {
|
2004-01-13 13:15:23 -08:00
|
|
|
int ret, type;
|
2004-01-20 08:19:45 -08:00
|
|
|
Ecore_Config_Bundle *t;
|
2004-01-13 13:15:23 -08:00
|
|
|
Ecore_Config_Prop *e;
|
2004-03-01 15:11:28 -08:00
|
|
|
t = __ecore_config_bundle_local;
|
2004-01-13 13:15:23 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
type=ecore_config_guess_type(key, val);
|
2004-01-13 13:15:23 -08:00
|
|
|
ret=ecore_config_default_typed(t, key, val, type);
|
2004-01-18 01:29:39 -08:00
|
|
|
e=ecore_config_get(t,key);
|
|
|
|
if (e) {
|
2004-01-13 13:15:23 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-01-18 01:29:39 -08:00
|
|
|
|
|
|
|
return ret;
|
2004-01-12 08:08:08 -08:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_int(const char *key,int val) {
|
2004-04-13 16:36:40 -07:00
|
|
|
return ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) &val, PT_INT);
|
2004-01-13 13:15:23 -08:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_int_bound(const char *key,int val,int low,int high,int step) {
|
|
|
|
Ecore_Config_Bundle *t;
|
2004-01-13 13:15:23 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
int ret;
|
2004-03-01 15:11:28 -08:00
|
|
|
t = __ecore_config_bundle_local;
|
2004-01-13 13:15:23 -08:00
|
|
|
|
2004-04-13 16:36:40 -07:00
|
|
|
ret=ecore_config_default_typed(t, key, (void *) &val, PT_INT);
|
2004-01-18 01:29:39 -08:00
|
|
|
e=ecore_config_get(t,key);
|
|
|
|
if (e) {
|
2004-01-13 13:15:23 -08:00
|
|
|
e->step=step;
|
|
|
|
e->flags|=PF_BOUNDS;
|
|
|
|
e->lo=low;
|
|
|
|
e->hi=high;
|
|
|
|
ecore_config_bound(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-01-12 08:08:08 -08:00
|
|
|
}
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_string(const char *key,char *val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) val, PT_STR);
|
2004-01-12 08:08:08 -08:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_float(const char *key,float val){
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) &val, PT_FLT);
|
2004-01-13 13:15:23 -08:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_float_bound(const char *key,float val,float low,float high,float step) {
|
2004-01-13 13:15:23 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
int ret;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
ret=ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) &val, PT_FLT);
|
|
|
|
e=ecore_config_get(__ecore_config_bundle_local,key);
|
2004-01-18 01:29:39 -08:00
|
|
|
if (e) {
|
2004-01-13 13:15:23 -08:00
|
|
|
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;
|
2004-01-12 08:08:08 -08:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_default_rgb(const char *key,char *val) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) val, PT_RGB);
|
2004-01-12 08:08:08 -08:00
|
|
|
}
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-04-22 16:38:19 -07:00
|
|
|
int ecore_config_default_theme(const char *key,char *val) {
|
|
|
|
return ecore_config_default_typed(__ecore_config_bundle_local, key, (void *) val, PT_THM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_listen(const char *name,const char *key,
|
|
|
|
Ecore_Config_Listener listener,int tag,void *data) {
|
|
|
|
Ecore_Config_Bundle *t;
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
Ecore_Config_Listener_List *l;
|
2004-03-01 15:11:28 -08:00
|
|
|
t = __ecore_config_bundle_local;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if(!t||!key)
|
|
|
|
return ECORE_CONFIG_ERR_NODATA;
|
|
|
|
|
|
|
|
if(!(e=ecore_config_get(t,key))) {
|
|
|
|
int ret=ecore_config_add(t,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(t,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,t);
|
|
|
|
|
|
|
|
return ECORE_CONFIG_ERR_SUCC; }
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_deaf(const char *name,const char *key,
|
|
|
|
Ecore_Config_Listener listener) {
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Prop *e;
|
|
|
|
Ecore_Config_Listener_List *l,*p;
|
2004-03-01 15:11:28 -08:00
|
|
|
int ret;
|
|
|
|
ret=ECORE_CONFIG_ERR_NOTFOUND;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
if(!__ecore_config_bundle_local||!key)
|
2003-12-05 08:57:32 -08:00
|
|
|
return ECORE_CONFIG_ERR_NODATA;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
if(!(e=ecore_config_get(__ecore_config_bundle_local,key)))
|
2003-12-05 08:57:32 -08:00
|
|
|
return ECORE_CONFIG_ERR_NOTFOUND;
|
|
|
|
|
|
|
|
for(p=NULL,l=e->listeners;l;p=l,l=l->next) {
|
2004-01-26 07:27:11 -08:00
|
|
|
if((name&&!strcmp(l->name,name))||(l->listener==listener)) {
|
2003-12-05 08:57:32 -08:00
|
|
|
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) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Bundle *eb;
|
|
|
|
eb=srv->bundles;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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) {
|
2004-03-01 15:11:28 -08:00
|
|
|
Ecore_Config_Bundle *ns;
|
|
|
|
ns=srv->bundles;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
2003-12-06 09:24:19 -08:00
|
|
|
Ecore_Config_Bundle *ecore_config_bundle_new(Ecore_Config_Server *srv,const char *identifier) {
|
2003-12-05 08:57:32 -08:00
|
|
|
Ecore_Config_Bundle *t;
|
2004-03-08 07:03:40 -08:00
|
|
|
static long ss;
|
|
|
|
ss=0; /* bundle unique serial */
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
if((t=malloc(sizeof(Ecore_Config_Bundle)))) {
|
|
|
|
memset(t,0,sizeof(Ecore_Config_Bundle));
|
|
|
|
|
|
|
|
t->identifier=identifier;
|
|
|
|
t->serial=++ss;
|
2003-12-06 09:24:19 -08:00
|
|
|
t->owner=srv->name;
|
2003-12-05 08:57:32 -08:00
|
|
|
t->next=srv->bundles;
|
|
|
|
srv->bundles=t;
|
|
|
|
}
|
|
|
|
return t; }
|
|
|
|
|
|
|
|
Ecore_Config_Server *do_init(char *name) {
|
2004-03-01 15:11:28 -08:00
|
|
|
return _ecore_config_ipc_init(name);
|
2003-12-05 08:57:32 -08:00
|
|
|
}
|
|
|
|
|
2004-01-19 16:45:52 -08:00
|
|
|
Ecore_Config_Server *ecore_config_init_local(char *name) {
|
2003-12-05 08:57:32 -08:00
|
|
|
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);
|
2004-01-18 01:29:39 -08:00
|
|
|
unlink(buf);
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return do_init(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ecore_Config_Server *ecore_config_init_global(char *name) {
|
|
|
|
char *p;
|
2004-03-01 15:11:28 -08:00
|
|
|
int global;
|
2003-12-05 08:57:32 -08:00
|
|
|
char *buf;
|
2004-03-01 15:11:28 -08:00
|
|
|
global=0;
|
2003-12-05 08:57:32 -08:00
|
|
|
|
|
|
|
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);
|
2004-01-18 01:29:39 -08:00
|
|
|
global = creat(buf, S_IRWXU);
|
|
|
|
if (global)
|
2003-12-05 08:57:32 -08:00
|
|
|
close(global);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return do_init(name);
|
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
int ecore_config_init(char *name) {
|
2004-01-19 16:45:52 -08:00
|
|
|
char *buf, *p;
|
2004-02-03 14:53:13 -08:00
|
|
|
Ecore_Config_Prop *sys;
|
2004-01-19 16:45:52 -08:00
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
__ecore_config_app_name = strdup(name);
|
|
|
|
__ecore_config_server_local = ecore_config_init_local(name);
|
|
|
|
if (!__ecore_config_server_local)
|
2004-01-31 23:28:09 -08:00
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
__ecore_config_server_global = ecore_config_init_global(ECORE_CONFIG_GLOBAL_ID);
|
|
|
|
if (!__ecore_config_server_global)
|
2004-01-31 23:28:09 -08:00
|
|
|
return ECORE_CONFIG_ERR_FAIL;
|
|
|
|
|
2004-03-01 15:11:28 -08:00
|
|
|
__ecore_config_bundle_local = ecore_config_bundle_new(__ecore_config_server_local, "config");
|
2004-01-19 16:45:52 -08:00
|
|
|
|
|
|
|
if((p=getenv("HOME"))) { /* debug-only ### FIXME */
|
|
|
|
if ((buf=malloc(PATH_MAX*sizeof(char)))) {
|
|
|
|
snprintf(buf,PATH_MAX,"%s/.e/config.db",p);
|
2004-01-31 23:28:09 -08:00
|
|
|
if (ecore_config_load_file(buf) != 0)
|
2004-02-01 15:54:08 -08:00
|
|
|
if (ecore_config_load_file(PACKAGE_DATA_DIR "/system.db") != 0)
|
|
|
|
return ECORE_CONFIG_ERR_NOFILE;
|
2004-03-01 15:11:28 -08:00
|
|
|
sys = __ecore_config_bundle_local->data;
|
2004-02-03 14:53:13 -08:00
|
|
|
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 */
|
2004-03-09 15:01:05 -08:00
|
|
|
sys->flags|=PF_SYSTEM;
|
2004-02-03 14:53:13 -08:00
|
|
|
sys=sys->next;
|
|
|
|
}
|
2004-01-19 16:45:52 -08:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2004-01-20 08:19:45 -08:00
|
|
|
return ECORE_CONFIG_ERR_SUCC;
|
2004-01-19 16:45:52 -08:00
|
|
|
}
|
|
|
|
|
2003-12-05 08:57:32 -08:00
|
|
|
int ecore_config_exit(void) {
|
2004-02-15 06:43:08 -08:00
|
|
|
int ret;
|
2004-03-01 15:11:28 -08:00
|
|
|
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);
|
2004-02-15 06:43:08 -08:00
|
|
|
return ret;
|
2003-12-05 08:57:32 -08:00
|
|
|
}
|
|
|
|
|