Morten Nilsen wrote:
Morten Nilsen wrote:
Here you have my second patch - I've really wanted this functionality,
so I decided to have a go at implementing it..
This patch also removes the theme path for "econfig" that is set by the
init function (and any others it might set) before loading the file
I've written a different version of this code, that sorts the list, but
still uses ecore_config_as_string_get to actually print info, so the
output isn't nicely tabulated..
However, I don't think this code is all that neat, and would like some
input on it...
I did some cleanup, and modified the switch from "ecore_config get" to
format the list output
Cheers,
--
Morten
#include <Ecore_Config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef PATHCMP
int pathcmp(const char *s1, const char *s2) {
int i = 0, j = 0, d = 0, c = 0;
char *s1d, *s2d;
s1d = malloc(512);
s2d = malloc(512);
while(*s1 && *s2) {
if(*s1 == '/') s1++;
i = 0;
while(*s1 && *s1 != '/') {
s1d[i++] = *s1++;
}
if(*s2 == '/') s2++;
j = 0;
while(*s2 && *s2 != '/') {
s2d[j++] = *s2++;
}
if(!*s1 && *s2 == '/')
return 1;
if(!*s2 && *s1 == '/')
return -1;
s1d[i] = 0;
s2d[j] = 0;
d = strcmp(s1d, s2d);
if(d != 0) {
return d;
}
}
return 0;
}
#endif
int main(int argc, char ** argv) {
if(argc != 2) {
printf("Usage: %s <ecore_config_file>\n", argv[0]);
return 1;
}
if (ecore_config_init("eec") != ECORE_CONFIG_ERR_SUCC) {
printf("Cannot init Ecore_Config");
return 1;
}
char **keys;
char *key;
int i = 0, x, y, klen = 0;
Ecore_Config_Bundle *t;
Ecore_Config_Prop *e;
char *temp;
keys = malloc(1024); // 1024 keys ought to be enough for anyone
t = __ecore_config_bundle_local;
while((e = t->data)) {
ecore_config_dst(e);
}
if(ecore_config_file_load(argv[1]) == ECORE_CONFIG_ERR_NODATA) {
printf("Unable to read config %s\n", argv[1]);
return 1;
}
// find all keys
e = t->data;
do {
keys[i++] = e->key;
if(strlen(e->key) > klen) klen = strlen(e->key);
} while((e = e->next));
// sort keys
for(x=0; x < i; ++x) {
for(y=0; y < i-1; ++y) {
#ifdef PATHCMP
if(pathcmp(keys[y],keys[y+1])>0) {
#else
if(strcmp(keys[y],keys[y+1])>0) {
#endif
temp = keys[y+1];
keys[y+1] = keys[y];
keys[y] = temp;
}
}
}
for(x=0; x < i; ++x) {
key = keys[x];
e = ecore_config_get(key); // This won't fail, list of keys were taken from
memory
switch (e->type) {
case ECORE_CONFIG_NIL:
printf("%-28s\tnil\n",key);
break;
case ECORE_CONFIG_INT:
printf("%-28s\tint\t%ld\n", key, ecore_config_int_get(key));
break;
case ECORE_CONFIG_BLN:
printf("%-28s\tbool\t%d\n", key, ecore_config_boolean_get(key));
break;
case ECORE_CONFIG_FLT:
printf("%-28s\tfloat\t%lf\n", key, ecore_config_float_get(key));
break;
case ECORE_CONFIG_STR:
printf("%-28s\tstring\t\"%s\"\n", key, ecore_config_string_get(key));
break;
case ECORE_CONFIG_RGB:
printf("%-28s\trgb\t\"%s\"\n", key, ecore_config_argbstr_get(key));
break;
case ECORE_CONFIG_THM:
printf("%-28s\ttheme\t\"%s\"\n", key, ecore_config_theme_get(key));
break;
default:
fprintf(stderr, "%s: Property has unrecognised type", key);
}
}
ecore_config_shutdown();
return 0;
}