Morten Nilsen wrote:
here's take 3;
and here, 4..
still using bubble sort, but it no longer has arbitrary limits on token size or number of keys..
this patch uses ecore_sheap and does away with the bubble sort.. 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 4 Dec 2005 02:35:53 -0000 @@ -7,6 +7,58 @@ #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; + + // 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 +112,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 +139,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(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 +241,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 +284,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