]>
Dogcows Code - chaz/openbox/blob - openbox/config.c
3f3c70c172ec159cb8a9cb0c240175d23928e08e
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(char *filename
, FILE *);
25 /* set up built in variables! and their default values! */
27 config_def_set(config_def_new("engine", Config_String
));
28 config_def_set(config_def_new("theme", Config_String
));
29 config_def_set(config_def_new("font", Config_String
));
30 config_def_set(config_def_new("font.shadow.offset", Config_Integer
));
31 config_def_set(config_def_new("font.shadow.tint", Config_Integer
));
32 config_def_set(config_def_new("titlebar.layout", Config_String
));
34 /*g_datalist_foreach(&config_def, print_config, NULL);*/
37 void config_shutdown()
39 g_datalist_clear(&config
);
40 g_datalist_clear(&config_def
);
48 /* load the system wide rc file first */
49 path
= g_build_filename(RCDIR
, "rc3", NULL
);
50 if ((file
= fopen(path
, "r")) != NULL
) {
51 cparse_go(path
, file
);
56 /* then load the user one which can override it */
57 path
= g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL
);
58 if ((file
= fopen(path
, "r")) != NULL
) {
59 cparse_go(path
, file
);
65 gboolean
config_set(char *name
, ConfigValueType type
, ConfigValue value
)
70 name
= g_ascii_strdown(name
, -1);
71 g_message("Setting %s", name
);
73 /*g_datalist_foreach(&config_def, print_config, NULL);*/
74 def
= g_datalist_get_data(&config_def
, name
);
77 g_message("Invalid config option '%s'", name
);
80 gboolean found
= FALSE
;
86 if (g_ascii_strcasecmp(it
->data
, value
.string
) == 0) {
90 } while ((it
= it
->next
));
93 g_message("Invalid value '%s' for config option '%s'",
103 config_set_entry(name
, type
, value
);
110 gboolean
config_get(char *name
, ConfigValueType type
, ConfigValue
*value
)
113 gboolean ret
= FALSE
;
115 name
= g_ascii_strdown(name
, -1);
116 entry
= g_datalist_get_data(&config
, name
);
117 if (entry
!= NULL
&& entry
->type
== type
) {
118 *value
= entry
->value
;
125 static void config_set_entry(char *name
, ConfigValueType type
,
128 ConfigEntry
*entry
= NULL
;
130 entry
= g_new(ConfigEntry
, 1);
133 if (type
== Config_String
)
134 entry
->value
.string
= g_strdup(value
.string
);
136 entry
->value
= value
;
138 g_datalist_set_data_full(&config
, name
, entry
,
139 (GDestroyNotify
)config_free_entry
);
142 static void config_free_entry(ConfigEntry
*entry
)
146 if(entry
->type
== Config_String
) {
147 g_free(entry
->value
.string
);
148 entry
->value
.string
= NULL
;
153 ConfigDefEntry
*config_def_new(char *name
, ConfigValueType type
)
155 ConfigDefEntry
*entry
;
157 entry
= g_new(ConfigDefEntry
, 1);
158 entry
->name
= g_ascii_strdown(name
, -1);
159 entry
->hasList
= FALSE
;
161 entry
->values
= NULL
;
165 static void config_def_free(ConfigDefEntry
*entry
)
170 if (entry
->hasList
) {
171 for (it
= entry
->values
; it
!= NULL
; it
= it
->next
)
173 g_slist_free(entry
->values
);
178 gboolean
config_def_add_value(ConfigDefEntry
*entry
, char *value
)
180 if (entry
->type
!= Config_String
) {
181 g_warning("Tried adding value to non-string config definition");
185 entry
->hasList
= TRUE
;
186 entry
->values
= g_slist_append(entry
->values
, g_ascii_strdown(value
, -1));
190 gboolean
config_def_set(ConfigDefEntry
*entry
)
192 gboolean ret
= FALSE
;
195 if ((def
= g_datalist_get_data(&config_def
, entry
->name
))) {
196 g_assert(def
!= entry
); /* adding it twice!? */
197 g_warning("Definition already set for config option '%s'. ",
199 config_def_free(entry
);
201 g_datalist_set_data_full(&config_def
, entry
->name
, entry
,
202 (GDestroyNotify
)config_def_free
);
This page took 0.044128 seconds and 4 git commands to generate.