void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, bool takes_on_off, GClosure *get_tostring_fn, GClosure *set_fromstring_fn) { owl_variable *var = owl_variable_newvar(OWL_VARIABLE_OTHER, name, summary, description, validsettings); var->takes_on_off = takes_on_off; var->get_tostring_fn = g_closure_ref(get_tostring_fn); g_closure_sink(get_tostring_fn); var->set_fromstring_fn = g_closure_ref(set_fromstring_fn); g_closure_sink(set_fromstring_fn); var->default_str = owl_variable_get_tostring(var); /* Note: this'll overwrite any existing variable of that name, even a C one, but it's consistent with previous behavior and commands. */ owl_variable_dict_add_variable(vd, var); }
void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) { owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING); if(old) { owl_variable_update(old, summ, desc); if(old->pval_default) owl_free(old->pval_default); old->pval_default = owl_strdup(initval); } else { owl_variable * var = owl_variable_newvar(name, summ, desc); var->type = OWL_VARIABLE_STRING; var->pval_default = owl_strdup(initval); var->set_fn = owl_variable_string_set_default; var->set_fromstring_fn = owl_variable_string_set_fromstring_default; var->get_fn = owl_variable_get_default; var->get_tostring_fn = owl_variable_string_get_tostring_default; var->free_fn = owl_variable_free_default; var->set_fn(var, initval); owl_variable_dict_add_variable(vd, var); } }
void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) { owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL); if(old) { owl_variable_update(old, summ, desc); old->ival_default = initval; } else { owl_variable * var = owl_variable_newvar(name, summ, desc); var->type = OWL_VARIABLE_BOOL; var->ival_default = initval; var->validate_fn = owl_variable_bool_validate_default; var->set_fn = owl_variable_bool_set_default; var->set_fromstring_fn = owl_variable_bool_set_fromstring_default; var->get_fn = owl_variable_get_default; var->get_tostring_fn = owl_variable_bool_get_tostring_default; var->free_fn = owl_variable_free_default; var->val = owl_malloc(sizeof(int)); var->set_fn(var, &initval); owl_variable_dict_add_variable(vd, var); } }
void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT); if(old) { owl_variable_update(old, summ, desc); old->ival_default = initval; } else { owl_variable * var = owl_variable_newvar(name, summ, desc); var->type = OWL_VARIABLE_INT; var->ival_default = initval; var->validate_fn = owl_variable_int_validate_default; var->set_fn = owl_variable_int_set_default; var->set_fromstring_fn = owl_variable_int_set_fromstring_default; var->get_fn = owl_variable_get_default; var->get_tostring_fn = owl_variable_int_get_tostring_default; var->delete_fn = owl_variable_delete_default; var->val = g_new(int, 1); var->set_fn(var, &initval); owl_variable_dict_add_variable(vd, var); } }
static void owl_variable_dict_newvar_enum_full(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description, const char *validsettings, validate_int_t validate_fn, set_int_t set_fn, get_int_t get_fn) { owl_variable *var = owl_variable_newvar(OWL_VARIABLE_INT, name, summary, description, validsettings); var->takes_on_off = false; var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_int_get_default); var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_int_set_default); var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_enum_validate); var->get_tostring_fn = owl_variable_make_closure( var, G_CALLBACK(owl_variable_enum_get_tostring), g_cclosure_user_marshal_STRING__VOID); var->set_fromstring_fn = owl_variable_make_closure( var, G_CALLBACK(owl_variable_enum_set_fromstring), g_cclosure_user_marshal_INT__STRING); g_value_init(&var->val, G_TYPE_INT); owl_variable_set_int(var, default_val); var->default_str = owl_variable_get_tostring(var); owl_variable_dict_add_variable(vd, var); }
static void owl_variable_dict_newvar_bool_full(owl_vardict *vd, const char *name, bool default_val, const char *summary, const char *description, validate_bool_t validate_fn, set_bool_t set_fn, get_bool_t get_fn) { owl_variable *var = owl_variable_newvar(OWL_VARIABLE_BOOL, name, summary, description, "on,off"); var->takes_on_off = true; var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_bool_get_default); var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_bool_set_default); var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_bool_validate_default); var->get_tostring_fn = owl_variable_make_closure( var, G_CALLBACK(owl_variable_bool_get_tostring_default), g_cclosure_user_marshal_STRING__VOID); var->set_fromstring_fn = owl_variable_make_closure( var, G_CALLBACK(owl_variable_bool_set_fromstring_default), g_cclosure_user_marshal_INT__STRING); g_value_init(&var->val, G_TYPE_BOOLEAN); owl_variable_set_bool(var, default_val); var->default_str = owl_variable_get_tostring(var); owl_variable_dict_add_variable(vd, var); }