7 static void config_free_entry(ConfigEntry *entry);
8 static void config_set_entry(char *name, ConfigValueType type,
10 static void config_def_free(ConfigDefEntry *entry);
11 static void print_config(GQuark q, gpointer data, gpointer fonk){
12 ConfigDefEntry *e = (ConfigDefEntry *)data;
13 g_message("config: %s %d", e->name, e->hasList);
16 static GData *config = NULL;
17 static GData *config_def = NULL;
19 /* provided by cparse.l */
20 void cparse_go(FILE *);
28 def = config_def_new("test", Config_String);
31 def = config_def_new("test", Config_String);
34 def = config_def_new("testlist", Config_String);
35 config_def_add_value(def, "one");
36 config_def_add_value(def, "two");
39 g_datalist_foreach(&config_def, print_config, NULL);
42 void config_shutdown()
44 g_datalist_clear(&config);
45 g_datalist_clear(&config_def);
53 /* load the system wide rc file first */
54 path = g_build_filename(RCDIR, "rc3", NULL);
55 if ((file = fopen(path, "r")) != NULL) {
61 /* then load the user one which can override it */
62 path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
63 if ((file = fopen(path, "r")) != NULL) {
70 gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
75 name = g_ascii_strdown(name, -1);
76 g_message("Setting %s", name);
78 g_datalist_foreach(&config_def, print_config, NULL);
79 def = g_datalist_get_data(&config_def, name);
82 g_message("Invalid config option '%s'", name);
85 gboolean found = FALSE;
91 if (g_ascii_strcasecmp(it->data, value.string) == 0) {
95 } while ((it = it->next));
98 g_message("Invalid value '%s' for config option '%s'",
108 config_set_entry(name, type, value);
115 gboolean config_get(char *name, ConfigValueType type, ConfigValue *value)
118 gboolean ret = FALSE;
120 name = g_ascii_strdown(name, -1);
121 entry = g_datalist_get_data(&config, name);
122 if (entry != NULL && entry->type == type) {
123 *value = entry->value;
130 static void config_set_entry(char *name, ConfigValueType type,
133 ConfigEntry *entry = NULL;
135 entry = g_new(ConfigEntry, 1);
138 if (type == Config_String)
139 entry->value.string = g_strdup(value.string);
141 entry->value = value;
143 g_datalist_set_data_full(&config, name, entry,
144 (GDestroyNotify)config_free_entry);
147 static void config_free_entry(ConfigEntry *entry)
151 if(entry->type == Config_String) {
152 g_free(entry->value.string);
153 entry->value.string = NULL;
158 ConfigDefEntry *config_def_new(char *name, ConfigValueType type)
160 ConfigDefEntry *entry;
162 entry = g_new(ConfigDefEntry, 1);
163 entry->name = g_ascii_strdown(name, -1);
164 entry->hasList = FALSE;
166 entry->values = NULL;
170 static void config_def_free(ConfigDefEntry *entry)
175 if (entry->hasList) {
176 for (it = entry->values; it != NULL; it = it->next)
178 g_slist_free(entry->values);
183 gboolean config_def_add_value(ConfigDefEntry *entry, char *value)
185 if (entry->type != Config_String) {
186 g_warning("Tried adding value to non-string config definition");
190 entry->hasList = TRUE;
191 entry->values = g_slist_append(entry->values, g_ascii_strdown(value, -1));
195 gboolean config_def_set(ConfigDefEntry *entry)
197 gboolean ret = FALSE;
200 if ((def = g_datalist_get_data(&config_def, entry->name))) {
201 g_assert(def != entry); /* adding it twice!? */
202 g_warning("Definition already set for config option '%s'. ",
204 config_def_free(entry);
206 g_datalist_set_data_full(&config_def, entry->name, entry,
207 (GDestroyNotify)config_def_free);