xnowfall wrote:
is there currently no way to delete keys with ecore_config? i was trying to patch the entrance ebuild which still modifies entrance_config.db with edb_ed, but that needs to delete a few keys...
here's a patch I just whipped up.. it includes a bit I did when I implemented list, that nukes ecore_config config (path stuff)
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 3 Dec 2005 00:59:01 -0000 @@ -35,6 +85,17 @@ } int +del(const char *key) +{ + Ecore_Config_Prop *e; + e = ecore_config_get(key); + if(e == NULL) return -1; + + ecore_config_dst(e); + return 0; +} + +int get(const char *key) { Ecore_Config_Prop *e; @@ -143,8 +243,9 @@ usage_and_exit(const char *prog, int ret, const char *msg) { if (msg) fprintf(stderr, msg); - fprintf(stderr, "Usage: %s <config-file> {get|set|type|list} [args...]\n", prog); + fprintf(stderr, "Usage: %s <config-file> {get|del|set|type|list} [args...]\n", prog); fprintf(stderr, "LIST: %s <config-file> list\n", prog); + fprintf(stderr, "DEL: %s <config-file> del <key>\n", prog); fprintf(stderr, "GET: %s <config-file> get <key>\n", prog); fprintf(stderr, "GET TYPE: %s <config-file> type <key>\n", prog); fprintf(stderr, "SET: %s <config-file> set <key> {nil|int|float|bool|str|rgb|theme} <value>\n", prog); @@ -154,6 +255,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; @@ -169,13 +272,14 @@ if (strcmp("get", cmd) && strcmp("type", cmd) && strcmp("set", cmd) && - strcmp("list", cmd)) + strcmp("list", cmd) && + strcmp("del", cmd)) { usage_and_exit(prog, 2, "Unrecognised command\n"); } // Check for enough arguments - if ((*cmd == 's') || (*cmd == 'g') || (*cmd == 't')) { + if ((*cmd == 's') || (*cmd == 'g') || (*cmd == 't') || (*cmd == 'd')) { if (argc < 3) usage_and_exit(prog, 2, "Not enough arguments\n"); key = argv[3]; } @@ -194,8 +298,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 @@ -208,6 +319,14 @@ ecore_config_file_save(file); } break; + case 'd': + if(del(key)) { + fprintf(stderr, "Del failed\n"); + ret = 4; + } else { + ecore_config_file_save(file); + } + break; case 'g': if (get(key)) ret = 4; break;