Morten Nilsen wrote:
Morten Nilsen wrote:
+       keys = ecore_sheap_new(SORT_CMP, eet_num_entries(ef));

should be ECORE_COMPARE_CB(SORT_CMP) to remove a compiler warning

 > + while(key = ecore_sheap_extract(keys)) {

should be while((..)) { to remove another warning


find attached a new patch, with above corrections, and a better path_cmp implementation.

Cheers,
--
Morten
:wq
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      4 Dec 2005 04:31:16 -0000
@@ -7,6 +7,46 @@
 
 #ifdef BUILD_ECORE_CONFIG
 #include "Ecore_Config.h"
+#include "Ecore_Data.h"
+#include <Eet.h>
+
+#ifndef SORT_CMP
+#define 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;
+
+       // strip common part of path
+       while(*s1 && *s2 && *s1 == *s2) {
+               s1++;
+               s2++;
+       }
+
+       // skip leading /
+       if(*s1 == '/') s1++;
+       if(*s2 == '/') s2++;
+
+       // order folders before files
+       s1d = strchr(s1, '/');
+       s2d = strchr(s2, '/');
+       if(s1d == NULL && s2d != NULL) return  1;
+       if(s1d != NULL && s2d == NULL) return -1;
+
+       // Perform regular strcmp of tokens
+       i = strcmp(s1, s2);
+
+       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 +100,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 +127,31 @@
 int
 list(const char *file)
 {
-       fprintf(stderr, "Command not yet supported\n");
-       return -1;
+       char *key;
+
+       Eet_File *ef;
+       Ecore_Config_Prop *e;
+       Ecore_Sheap *keys;
+
+       ef = eet_open(file, EET_FILE_MODE_READ);
+       if (!ef) return -1;
+
+       keys = ecore_sheap_new(ECORE_COMPARE_CB(SORT_CMP), eet_num_entries(ef));
+
+       eet_close(ef);
+
+       e = __ecore_config_bundle_local->data;
+
+       do {
+               ecore_sheap_insert(keys, e->key);
+       } while((e = e->next));
+
+       while((key = ecore_sheap_extract(keys))) {
+               printf("%-28s\t", key);
+               get(key);
+       }
+
+       return 0;
 }
 
 int
@@ -154,6 +229,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 +272,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

Reply via email to