radare2/libr/config/callback.c
pancake 3d142e8ec1 * Initial import of the hashtable implementation of WayLand
- Kinda smart (150LOC)
  - Fork it for 64bit hash keys (make ht64 in libr/util)
* Make RConfig use the RHashTable to resolve by name
  - Code cleanup resulting in -30LOC
  - O(1) access to config variables (speedup!)
  - Make r_list_free and r_list_destroy take sense
2011-03-17 19:05:39 +01:00

56 lines
1.4 KiB
C

/* radare - LGPL - Copyright 2006-2011 pancake<nopcode.org> */
#include "r_config.h"
// XXX spaguetti code lives here
static int r_config_callback_q(void *data) {
RConfigNode *node = data;
*(node->cb_ptr_q) = node->i_value;
return R_TRUE;
}
static int r_config_callback_i(void *data) {
RConfigNode *node = data;
*(node->cb_ptr_i) = node->i_value;
return R_TRUE;
}
static int r_config_callback_s(void *data) {
RConfigNode *node = data;
if (!node->value || !*node->value) {
free (*node->cb_ptr_s);
*node->cb_ptr_s = NULL;
} else *node->cb_ptr_s = r_str_dup (*node->cb_ptr_s, node->value);
return R_TRUE;
}
R_API int r_config_set_callback_q(RConfig *cfg, const char *name, ut64 *ptr) {
RConfigNode *node = r_config_node_get (cfg, name);
if (node) {
node->cb_ptr_q = ptr;
node->callback = (void *)&r_config_callback_q;
return R_TRUE;
}
return R_FALSE;
}
R_API int r_config_set_callback_i(RConfig *cfg, const char *name, int *ptr) {
RConfigNode *node = r_config_node_get (cfg, name);
if (node) {
node->cb_ptr_i = ptr;
node->callback = (void *)&r_config_callback_i;
return R_TRUE;
}
return R_FALSE;
}
R_API int r_config_set_callback_s(RConfig *cfg, const char *name, char **ptr) {
RConfigNode *node = r_config_node_get (cfg, name);
if (node) {
node->cb_ptr_s = ptr;
node->callback = (void *)&r_config_callback_s;
return R_TRUE;
}
return R_FALSE;
}