2008-06-28 18:37:28 +00:00
|
|
|
|
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
option* option_new_bool(gboolean val) {
|
|
|
|
option *opt = g_slice_new0(option);
|
|
|
|
opt->value.opt_bool = val;
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
option* option_new_int(gint val) {
|
|
|
|
option *opt = g_slice_new0(option);
|
|
|
|
opt->value.opt_int = val;
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
option* option_new_string(GString *val) {
|
|
|
|
option *opt = g_slice_new0(option);
|
|
|
|
opt->value.opt_string = val;
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
option* option_new_list() {
|
|
|
|
option *opt = g_slice_new0(option);
|
|
|
|
opt->value.opt_list = g_array_new(FALSE, TRUE, sizeof(option*));
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _option_hash_free_key(gpointer data) {
|
|
|
|
g_string_free((GString*) data, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _option_hash_free_value(gpointer data) {
|
|
|
|
option_free((option*) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
option* option_new_hash() {
|
|
|
|
option *opt = g_slice_new0(option);
|
|
|
|
opt->value.opt_hash = g_hash_table_new_full(
|
|
|
|
(GHashFunc) g_string_hash, (GEqualFunc) g_string_equal,
|
|
|
|
_option_hash_free_key, _option_hash_free_value);
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void option_free(option* opt) {
|
2008-07-08 17:44:55 +00:00
|
|
|
guint i;
|
|
|
|
|
2008-06-28 18:37:28 +00:00
|
|
|
if (!opt) return;
|
|
|
|
|
|
|
|
switch (opt->type) {
|
|
|
|
case OPTION_NONE:
|
|
|
|
case OPTION_BOOLEAN:
|
|
|
|
case OPTION_INT:
|
|
|
|
/* Nothing to free */
|
|
|
|
break;
|
|
|
|
case OPTION_STRING:
|
|
|
|
g_string_free(opt->value.opt_string, TRUE);
|
|
|
|
break;
|
|
|
|
case OPTION_LIST:
|
2008-07-08 17:44:55 +00:00
|
|
|
for (i=0; i<opt->value.opt_list->len; i++)
|
2008-07-08 17:47:10 +00:00
|
|
|
option_free(g_array_index(opt->value.opt_list, option *, i));
|
2008-07-08 17:44:55 +00:00
|
|
|
g_array_free(opt->value.opt_list, FALSE);
|
2008-06-28 18:37:28 +00:00
|
|
|
break;
|
|
|
|
case OPTION_HASH:
|
2008-07-08 17:44:55 +00:00
|
|
|
g_hash_table_destroy(opt->value.opt_hash);
|
2008-06-28 18:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
opt->type = OPTION_NONE;
|
|
|
|
g_slice_free(option, opt);
|
|
|
|
}
|