dan sinclair wrote:
Why the 1000 key limit? Is that an ecore_config limit or something that you
just made up? Bubblesort may not be a good choice for this as it maybe too
slow. One option is to use the ecore heap implementation and dump it to a list.
EWL does this to sort files I believe. It's nice and fast. (And since we're in
ecore we can probably use ecore_data.)
Also looks like your forcing a max key length to 512 in the case of pathcmp
correct? Is this an ecore_config limit or something your imposing.
Would be nice to get rid of the 1000 key limit as all of the OVERFLOW code is pretty gross looking in there.
here's take 3;
still using bubble sort, but it no longer has arbitrary limits on token
size or number of keys..
like before, comments appreciated :)
Cheers,
--
Morten
Index: ecore_config.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/bin/ecore_config.c,v
retrieving revision 1.3
diff -u -r1.3 ecore_config.c
--- ecore_config.c 18 Sep 2005 12:48:24 -0000 1.3
+++ ecore_config.c 30 Nov 2005 02:33:33 -0000
@@ -8,6 +8,56 @@
#ifdef BUILD_ECORE_CONFIG
#include "Ecore_Config.h"
+#ifndef BUBBLE_SORT_CMP
+#define BUBBLE_SORT_CMP pathcmp
+#endif
+
+// strcmp for paths - for sorting folders before files
+int pathcmp(const char *s1, const char *s2)
+{
+ int i = 0;
+ char *s1d, *s2d;
+
+ // alloc potential maximum size of tokens
+ s1d = malloc(strlen(s1) + 1);
+ s2d = malloc(strlen(s2) + 1);
+
+ while(*s1 && *s2) {
+
+ // skip leading /
+ if(*s1 == '/') s1++;
+ if(*s2 == '/') s2++;
+
+ // get one token from s1
+ i = 0;
+ while(s1[i++] && s1[i] != '/');
+ strncpy(s1d, s1, i);
+ s1d[i] = 0;
+ s1 += i;
+
+ // get one token from s2
+ i = 0;
+ while(s2[i++] && s2[i] != '/');
+ strncpy(s2d, s2, i);
+ s2d[i] = 0;
+ s2 += i;
+
+ // These returns order folders before files
+ if(!*s1 && *s2 == '/') return 1;
+ if(!*s2 && *s1 == '/') return -1;
+
+ // Perform regular strcmp of tokens
+ i = strcmp(s1d, s2d);
+
+ if(i != 0) {
+ return i;
+ }
+ }
+ // We should never come here...
+ fprintf(stderr,"Equal path!");
+ return 0;
+}
+
int
set(const char *key, int ec_type, const char *value)
{
@@ -49,22 +99,22 @@
printf("\n");
break;
case ECORE_CONFIG_INT:
- printf("%ld\n", ecore_config_int_get(key));
+ printf("int\t%ld\n", ecore_config_int_get(key));
break;
case ECORE_CONFIG_BLN:
- printf("%d\n", ecore_config_boolean_get(key));
+ printf("bool\t%d\n", ecore_config_boolean_get(key));
break;
case ECORE_CONFIG_FLT:
- printf("%lf\n", ecore_config_float_get(key));
+ printf("float\t%lf\n", ecore_config_float_get(key));
break;
case ECORE_CONFIG_STR:
- printf("%s\n", ecore_config_string_get(key));
+ printf("string\t\"%s\"\n", ecore_config_string_get(key));
break;
case ECORE_CONFIG_RGB:
- printf("%s\n", ecore_config_argbstr_get(key));
+ printf("rgb\t\"%s\"\n", ecore_config_argbstr_get(key));
break;
case ECORE_CONFIG_THM:
- printf("%s\n", ecore_config_theme_get(key));
+ printf("theme\t\"%s\"\n", ecore_config_theme_get(key));
break;
default:
fprintf(stderr, "Property has unrecognised type");
@@ -76,8 +126,47 @@
int
list(const char *file)
{
- fprintf(stderr, "Command not yet supported\n");
- return -1;
+ Ecore_Config_Prop *e;
+ e = __ecore_config_bundle_local->data;
+
+ int c = 10, n = -1, x, y;
+ char **keys;
+ char *temp;
+
+ keys = (char **)malloc(c * sizeof(char *));
+
+ // Collect keys in array for sorting
+ do {
+ // allocate blocks of 10 pointers as needed
+ if(++n > c) {
+ c += 10;
+ keys = (char **)realloc(keys, c * sizeof(char *));
+ if(keys == NULL) {
+ fprintf(stderr, "Out of memory");
+ return -1;
+ }
+ }
+ keys[n] = e->key;
+ } while((e = e->next));
+
+ // Bubble sort
+ for(x=0; x < n; ++x) {
+ for(y=0; y < n-1; ++y) {
+ if(BUBBLE_SORT_CMP(keys[y],keys[y+1])>0) {
+ temp = keys[y+1];
+ keys[y+1] = keys[y];
+ keys[y] = temp;
+ }
+ }
+ }
+
+ // do output
+ for(x=0; x < n; ++x) {
+ printf("%-28s\t", keys[x]);
+ get(keys[x]);
+ }
+
+ return 0;
}
int
@@ -154,6 +243,8 @@
int
main(int argc, const char **argv)
{
+ Ecore_Config_Bundle *t;
+ Ecore_Config_Prop *e;
const char *prog, *file, *cmd, *key, *type, *value;
int ec_type = -1;
int ret = 0;
@@ -194,8 +285,15 @@
}
}
- // Load configuration from file
ecore_config_init("econfig");
+
+ // Remove any config not from the file
+ t = __ecore_config_bundle_local;
+ while((e = t->data)) {
+ ecore_config_dst(e);
+ }
+
+ // Load configuration from file
ecore_config_file_load(file);
// Execute command