/* creates a new command alias */ void owl_cmddict_add_alias(owl_cmddict *cd, const char *alias_from, const char *alias_to) { owl_cmd *cmd; cmd = g_new(owl_cmd, 1); owl_cmd_create_alias(cmd, alias_from, alias_to); owl_perlconfig_new_command(cmd->name); owl_dict_insert_element(cd, cmd->name, cmd, (void (*)(void *))owl_cmd_delete); }
void owl_global_add_filter(owl_global *g, owl_filter *f) { owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1); e->g = g; e->f = f; owl_dict_insert_element(&(g->filters), owl_filter_get_name(f), e, owl_global_delete_filter_ent); g->filterlist = g_list_append(g->filterlist, f); }
int owl_cmddict_add_cmd(owl_cmddict *cd, const owl_cmd * cmd) { owl_cmd * newcmd = g_new(owl_cmd, 1); if(owl_cmd_create_from_template(newcmd, cmd) < 0) { g_free(newcmd); return -1; } owl_perlconfig_new_command(cmd->name); return owl_dict_insert_element(cd, newcmd->name, newcmd, (void (*)(void *))owl_cmd_delete); }
void owl_global_add_style(owl_global *g, owl_style *s) { /* * If we're redefining the current style, make sure to update * pointers to it. */ if(g->current_view.style && !strcmp(owl_style_get_name(g->current_view.style), owl_style_get_name(s))) g->current_view.style = s; owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), s, (void (*)(void *))owl_style_delete); }
int owl_dict_regtest(void) { owl_dict d; owl_list l; int numfailed=0; char *av="aval", *bv="bval", *cv="cval", *dv="dval"; printf("# BEGIN testing owl_dict\n"); FAIL_UNLESS("create", 0==owl_dict_create(&d)); FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete)); FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete)); FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_delete)); FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_delete)); FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0)); FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a")); FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b")); FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c")); FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d")); FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e")); FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d")); FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d")); FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d)); FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l)); FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l)); /* these assume the returned keys are sorted */ FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0))); FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1))); FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2))); owl_list_cleanup(&l, owl_free); owl_dict_cleanup(&d, NULL); /* if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */ printf("# END testing owl_dict (%d failures)\n", numfailed); return(numfailed); }
void owl_variable_dict_add_variable(owl_vardict * vardict, owl_variable * var) { char *oldvalue = NULL; owl_variable *oldvar = owl_variable_get_var(vardict, var->name); /* Save the old value as a string. */ if (oldvar) { oldvalue = owl_variable_get_tostring(oldvar); } owl_dict_insert_element(vardict, var->name, var, (void (*)(void *))owl_variable_delete); /* Restore the old value. */ if (oldvalue) { owl_variable_set_fromstring(var, oldvalue, 0); g_free(oldvalue); } }
void owl_variable_dict_add_variable(owl_vardict * vardict, owl_variable * var) { owl_dict_insert_element(vardict, var->name, (void*)var, (void(*)(void*))owl_variable_free); }
int owl_variable_dict_setup(owl_vardict *vd) { owl_variable *var, *cur; if (owl_dict_create(vd)) return(-1); for (var = variables_to_init; var->name != NULL; var++) { cur = owl_malloc(sizeof(owl_variable)); memcpy(cur, var, sizeof(owl_variable)); switch (cur->type) { case OWL_VARIABLE_OTHER: cur->set_fn(cur, cur->pval_default); break; case OWL_VARIABLE_STRING: if (!cur->validate_fn) cur->validate_fn = owl_variable_string_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_string_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_string_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_string_get_tostring_default; if (!cur->free_fn) cur->free_fn = owl_variable_free_default; cur->set_fn(cur, cur->pval_default); break; case OWL_VARIABLE_BOOL: if (!cur->validate_fn) cur->validate_fn = owl_variable_bool_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_bool_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_bool_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_bool_get_tostring_default; if (!cur->free_fn) cur->free_fn = owl_variable_free_default; cur->val = owl_malloc(sizeof(int)); cur->set_fn(cur, &cur->ival_default); break; case OWL_VARIABLE_INT: if (!cur->validate_fn) cur->validate_fn = owl_variable_int_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_int_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_int_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_int_get_tostring_default; if (!cur->free_fn) cur->free_fn = owl_variable_free_default; cur->val = owl_malloc(sizeof(int)); cur->set_fn(cur, &cur->ival_default); break; default: fprintf(stderr, "owl_variable_setup: invalid variable type\n"); return(-2); } owl_dict_insert_element(vd, cur->name, (void*)cur, NULL); } return 0; }
int owl_variable_dict_setup(owl_vardict *vd) { owl_variable *var, *cur; if (owl_dict_create(vd)) return(-1); for (var = variables_to_init; var->name != NULL; var++) { cur = g_new(owl_variable, 1); *cur = *var; /* strdup all the strings so we can delete them consistently. */ cur->name = g_strdup(var->name); cur->summary = g_strdup(var->summary); cur->description = g_strdup(var->description); switch (cur->type) { case OWL_VARIABLE_OTHER: cur->set_fn(cur, cur->pval_default); break; case OWL_VARIABLE_STRING: if (!cur->validate_fn) cur->validate_fn = owl_variable_string_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_string_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_string_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_string_get_tostring_default; if (!cur->delete_fn) cur->delete_fn = owl_variable_delete_default; cur->set_fn(cur, cur->pval_default); break; case OWL_VARIABLE_BOOL: if (!cur->validate_fn) cur->validate_fn = owl_variable_bool_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_bool_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_bool_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_bool_get_tostring_default; if (!cur->delete_fn) cur->delete_fn = owl_variable_delete_default; cur->val = g_new(int, 1); cur->set_fn(cur, &cur->ival_default); break; case OWL_VARIABLE_INT: if (!cur->validate_fn) cur->validate_fn = owl_variable_int_validate_default; if (!cur->set_fn) cur->set_fn = owl_variable_int_set_default; if (!cur->set_fromstring_fn) cur->set_fromstring_fn = owl_variable_int_set_fromstring_default; if (!cur->get_fn) cur->get_fn = owl_variable_get_default; if (!cur->get_tostring_fn) cur->get_tostring_fn = owl_variable_int_get_tostring_default; if (!cur->delete_fn) cur->delete_fn = owl_variable_delete_default; cur->val = g_new(int, 1); cur->set_fn(cur, &cur->ival_default); break; default: fprintf(stderr, "owl_variable_setup: invalid variable type\n"); return(-2); } owl_dict_insert_element(vd, cur->name, cur, NULL); } return 0; }
/* adds a new keymap */ void owl_keyhandler_add_keymap(owl_keyhandler *kh, owl_keymap *km) { owl_dict_insert_element(&kh->keymaps, km->name, km, NULL); }