8 #ifdef BUILD_ECORE_CONFIG
12 #include "Ecore_Config.h"
13 #include "Ecore_Data.h"
14 #include "ecore_config_private.h"
16 // strcmp for paths - for sorting folders before files
18 pathcmp(const char *s1, const char *s2)
22 // strip common part of paths
23 while(*s1 && *s2 && *s1 == *s2)
29 // handle /foo/bar/baz <> /foo/bar_baz properly
30 if (*s1 == '/' && *s2 != '/') return -1;
31 if (*s1 != '/' && *s2 == '/') return 1;
37 // order folders before files
38 s1d = strchr(s1, '/');
39 s2d = strchr(s2, '/');
40 if (s1d != NULL && s2d == NULL) return -1;
41 if (s1d == NULL && s2d != NULL) return 1;
43 return strcmp(s1, s2);
50 e = ecore_config_get(key);
51 if(e == NULL) return -1;
63 if (!(e = ecore_config_get(key)))
65 fprintf(stderr, "No such property\n");
69 printf("%-10s", ecore_config_type_get(e));
73 case ECORE_CONFIG_NIL:
76 case ECORE_CONFIG_INT:
77 printf("%ld\n", ecore_config_int_get(key));
79 case ECORE_CONFIG_BLN:
80 printf("%d\n", ecore_config_boolean_get(key));
82 case ECORE_CONFIG_FLT:
83 printf("%lf\n", ecore_config_float_get(key));
85 case ECORE_CONFIG_STR:
86 temp = ecore_config_string_get(key);
88 case ECORE_CONFIG_RGB:
89 temp = ecore_config_argbstr_get(key);
91 case ECORE_CONFIG_THM:
92 temp = ecore_config_theme_get(key);
95 fprintf(stderr, "Property has unrecognized type");
100 printf("\"%s\"\n", temp);
107 list(const char *file)
112 Ecore_Config_Prop *e;
115 // Get number of keys and create heap for sort
116 ef = eet_open(file, EET_FILE_MODE_READ);
119 keys = ecore_sheap_new(ECORE_COMPARE_CB(pathcmp), eet_num_entries(ef));
123 e = __ecore_config_bundle_local->data;
127 // don't show system settings
128 if( !(e->flags & ECORE_CONFIG_FLAG_SYSTEM) )
129 ecore_sheap_insert(keys, e->key);
131 while((e = e->next));
133 while((key = ecore_sheap_extract(keys)))
135 printf("%-28s\t", key);
139 ecore_sheap_destroy(keys);
145 usage_and_exit(const char *prog, int ret, const char *msg)
147 if (msg) fprintf(stderr, "%s\n\n", msg);
148 fprintf(stderr, "Usage: %s <options> <command>\n", prog);
149 fprintf(stderr, "Modify ecore_config files\n\n");
150 fprintf(stderr, "Options:\n");
151 fprintf(stderr, " -c, --file=FILE config file\n");
152 fprintf(stderr, " -k, --key=KEY must be given for all commands except -a\n\n");
153 fprintf(stderr, "Commands:\n");
154 fprintf(stderr, " -a, --list get all keys\n");
155 fprintf(stderr, " -g, --get get key\n");
156 fprintf(stderr, " -d, --del delete key\n");
157 fprintf(stderr, " -b, --bool=VALUE set boolean\n");
158 fprintf(stderr, " -f, --float=VALUE set float\n");
159 fprintf(stderr, " -i, --int=VALUE set integer\n");
160 fprintf(stderr, " -r, --rgb=VALUE set RGBA\n");
161 fprintf(stderr, " -s, --string=VALUE set string\n");
162 fprintf(stderr, " -t, --theme=VALUE set theme\n\n");
167 main(int argc, char * const argv[])
169 char *prog, *file, *key;
170 void *value = (void *)NULL;
177 file = key = prog = NULL;
179 prog = strdup(argv[0]);
182 usage_and_exit(prog, 2, NULL);
186 static struct option long_options[] = {
192 {"float", 1, 0, 'f'},
195 {"string", 1, 0, 's'},
196 {"theme", 1, 0, 't'},
201 ret = getopt_long(argc, argv, "c:agdb:f:i:r:s:t:k:", long_options, NULL);
208 key = strdup(optarg);
212 usage_and_exit(prog, 2, "too many commands");
213 type = ECORE_CONFIG_NIL;
218 usage_and_exit(prog, 2, "too many commands");
219 type = ECORE_CONFIG_BLN;
225 usage_and_exit(prog, 2, "too many commands");
226 type = ECORE_CONFIG_INT;
232 usage_and_exit(prog, 2, "too many commands");
233 type = ECORE_CONFIG_FLT;
239 usage_and_exit(prog, 2, "too many commands");
240 type = ECORE_CONFIG_RGB;
241 i = (long) strtoul( (*optarg == '#') ? (optarg + 1) : optarg, NULL, 16 );
246 usage_and_exit(prog, 2, "too many commands");
247 type = ECORE_CONFIG_STR;
248 value = strdup(optarg);
252 usage_and_exit(prog, 2, "too many commands");
253 type = ECORE_CONFIG_THM;
254 value = strdup(optarg);
259 file = strdup(optarg);
270 if(cmd == 's' && type == -1)
271 usage_and_exit(prog, 2, "You need to specify a command!");
273 if(cmd != 'a' && key == NULL)
274 usage_and_exit(prog, 2, "You need to specify key!");
276 if(ecore_config_init("econfig") != ECORE_CONFIG_ERR_SUCC)
278 fprintf(stderr, "Couldn't init ecore_config!");
282 // Load configuration from file
283 ecore_config_file_load(file);
291 if (ecore_config_typed_set(key, value, type) != ECORE_CONFIG_ERR_SUCC)
293 fprintf(stderr, "Set failed for %s", key);
296 ecore_config_file_save(file);
298 get(key); // display value after setting it
303 fprintf(stderr, "Delete failed for %s", key);
306 ecore_config_file_save(file);
310 if (get(key)) ret = 1;
313 if (list(file)) ret = 1;
316 printf("Unhandled command '%c'\n", cmd);
319 ecore_config_shutdown();
321 if(type == ECORE_CONFIG_STR || type == ECORE_CONFIG_THM)
331 main(int argc, const char **argv)
333 printf("Ecore_config module not compiled. This program is empty.\n");