8 #ifdef BUILD_ECORE_CONFIG
12 #include "Ecore_Config.h"
13 #include "ecore_config_private.h"
15 // strcmp for paths - for sorting folders before files
17 pathcmp(const char *s1, const char *s2)
21 // strip common part of paths
22 while(*s1 && *s2 && *s1 == *s2)
28 // handle /foo/bar/baz <> /foo/bar_baz properly
29 if (*s1 == '/' && *s2 != '/') return -1;
30 if (*s1 != '/' && *s2 == '/') return 1;
36 // order folders before files
37 s1d = strchr(s1, '/');
38 s2d = strchr(s2, '/');
39 if (s1d != NULL && s2d == NULL) return -1;
40 if (s1d == NULL && s2d != NULL) return 1;
42 return strcmp(s1, s2);
49 e = ecore_config_get(key);
50 if(e == NULL) return -1;
62 if (!(e = ecore_config_get(key)))
64 EINA_LOG_ERR("No such property");
68 printf("%-10s", ecore_config_type_get(e));
72 case ECORE_CONFIG_NIL:
75 case ECORE_CONFIG_INT:
76 printf("%ld\n", ecore_config_int_get(key));
78 case ECORE_CONFIG_BLN:
79 printf("%d\n", ecore_config_boolean_get(key));
81 case ECORE_CONFIG_FLT:
82 printf("%lf\n", ecore_config_float_get(key));
84 case ECORE_CONFIG_STR:
85 temp = ecore_config_string_get(key);
87 case ECORE_CONFIG_RGB:
88 temp = ecore_config_argbstr_get(key);
90 case ECORE_CONFIG_THM:
91 temp = ecore_config_theme_get(key);
94 EINA_LOG_ERR("Property has unrecognized type");
99 printf("\"%s\"\n", temp);
106 list(const char *file)
108 Ecore_Config_Prop *e;
109 Eina_List *keys = NULL;
112 e = __ecore_config_bundle_local->data;
116 // don't show system settings
117 if( !(e->flags & ECORE_CONFIG_FLAG_SYSTEM) )
118 keys = eina_list_append(keys, e->key);
120 while((e = e->next));
121 keys = eina_list_sort(keys, -1, EINA_COMPARE_CB(pathcmp));
123 EINA_LIST_FREE(keys, key)
125 printf("%-28s\t", key);
133 usage_and_exit(const char *prog, int ret, const char *msg)
135 if (msg) fprintf(stderr, "%s\n\n", msg);
136 fprintf(stderr, "Usage: %s <options> <command>\n", prog);
137 fprintf(stderr, "Modify ecore_config files\n\n");
138 fprintf(stderr, "Options:\n");
139 fprintf(stderr, " -c, --file=FILE config file\n");
140 fprintf(stderr, " -k, --key=KEY must be given for all commands except -a\n\n");
141 fprintf(stderr, "Commands:\n");
142 fprintf(stderr, " -a, --list get all keys\n");
143 fprintf(stderr, " -g, --get get key\n");
144 fprintf(stderr, " -d, --del delete key\n");
145 fprintf(stderr, " -b, --bool=VALUE set boolean\n");
146 fprintf(stderr, " -f, --float=VALUE set float\n");
147 fprintf(stderr, " -i, --int=VALUE set integer\n");
148 fprintf(stderr, " -r, --rgb=VALUE set RGBA\n");
149 fprintf(stderr, " -s, --string=VALUE set string\n");
150 fprintf(stderr, " -t, --theme=VALUE set theme\n\n");
155 main(int argc, char * const argv[])
157 char *prog, *file, *key;
158 void *value = (void *)NULL;
165 file = key = prog = NULL;
167 prog = strdup(argv[0]);
170 usage_and_exit(prog, 2, NULL);
174 static struct option long_options[] = {
180 {"float", 1, 0, 'f'},
183 {"string", 1, 0, 's'},
184 {"theme", 1, 0, 't'},
189 ret = getopt_long(argc, argv, "c:agdb:f:i:r:s:t:k:", long_options, NULL);
196 key = strdup(optarg);
200 usage_and_exit(prog, 2, "too many commands");
201 type = ECORE_CONFIG_NIL;
206 usage_and_exit(prog, 2, "too many commands");
207 type = ECORE_CONFIG_BLN;
213 usage_and_exit(prog, 2, "too many commands");
214 type = ECORE_CONFIG_INT;
220 usage_and_exit(prog, 2, "too many commands");
221 type = ECORE_CONFIG_FLT;
227 usage_and_exit(prog, 2, "too many commands");
228 type = ECORE_CONFIG_RGB;
229 i = (long) strtoul( (*optarg == '#') ? (optarg + 1) : optarg, NULL, 16 );
234 usage_and_exit(prog, 2, "too many commands");
235 type = ECORE_CONFIG_STR;
236 value = strdup(optarg);
240 usage_and_exit(prog, 2, "too many commands");
241 type = ECORE_CONFIG_THM;
242 value = strdup(optarg);
247 file = strdup(optarg);
258 if(cmd == 's' && type == -1)
259 usage_and_exit(prog, 2, "You need to specify a command!");
261 if(cmd != 'a' && key == NULL)
262 usage_and_exit(prog, 2, "You need to specify key!");
264 if(ecore_config_init("econfig") != ECORE_CONFIG_ERR_SUCC)
266 EINA_LOG_ERR("Couldn't init ecore_config!");
270 // Load configuration from file
271 ecore_config_file_load(file);
279 if (ecore_config_typed_set(key, value, type) != ECORE_CONFIG_ERR_SUCC)
281 fprintf(stderr, "Set failed for %s", key);
284 ecore_config_file_save(file);
286 get(key); // display value after setting it
291 fprintf(stderr, "Delete failed for %s", key);
294 ecore_config_file_save(file);
298 if (get(key)) ret = 1;
301 if (list(file)) ret = 1;
304 EINA_LOG_ERR("Unhandled command '%c'", cmd);
307 ecore_config_shutdown();
309 if(type == ECORE_CONFIG_STR || type == ECORE_CONFIG_THM)
319 main(int argc, const char **argv)
321 printf("Ecore_config module not compiled. This program is empty.\n");