CONFIG_NODE *config_node_section_index(CONFIG_NODE *parent, const char *key, int index, int new_type) { CONFIG_NODE *node; int nindex; g_return_val_if_fail(parent != NULL, NULL); g_return_val_if_fail(is_node_list(parent), NULL); node = key == NULL ? NULL : config_node_find(parent, key); if (node != NULL) { g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL); nindex = g_slist_index(parent->value, node); if (index >= 0 && nindex != index && nindex <= g_slist_length(parent->value)) { /* move it to wanted position */ parent->value = g_slist_remove(parent->value, node); parent->value = g_slist_insert(parent->value, node, index); } return node; } if (new_type == -1) return NULL; node = g_new0(CONFIG_NODE, 1); parent->value = index < 0 ? g_slist_append(parent->value, node) : g_slist_insert(parent->value, node, index); node->type = new_type; node->key = key == NULL ? NULL : g_strdup(key); return node; }
/* Like config_list_find(), but return node instead of it's value */ CONFIG_NODE *config_list_find_node(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key) { CONFIG_NODE *node, *keynode; GSList *tmp; g_return_val_if_fail(rec != NULL, NULL); g_return_val_if_fail(key != NULL, NULL); g_return_val_if_fail(value_key != NULL, NULL); node = config_node_traverse(rec, section, FALSE); if (node == NULL || !is_node_list(node)) return NULL; for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->type != NODE_TYPE_BLOCK) continue; /* key matches value? */ keynode = config_node_find(node, key); if (keynode == NULL || keynode->type != NODE_TYPE_KEY || g_strcasecmp(keynode->value, value) != 0) continue; return config_node_find(node, value_key); } return NULL; }
/* Clear all data inside node, but leave the node */ void config_node_clear(CONFIG_REC *rec, CONFIG_NODE *node) { g_return_if_fail(node != NULL); g_return_if_fail(is_node_list(node)); while (node->value != NULL) config_node_remove(rec, node, ((GSList *) node->value)->data); }
/* Remove n'th node from a list */ void config_node_list_remove(CONFIG_REC *rec, CONFIG_NODE *node, int index) { CONFIG_NODE *child; g_return_if_fail(node != NULL); g_return_if_fail(is_node_list(node)); child = config_node_nth(node, index); if (child != NULL) config_node_remove(rec, node, child); }
/* Returns n'th node from list. */ CONFIG_NODE *config_node_nth(CONFIG_NODE *node, int index) { GSList *tmp; g_return_val_if_fail(node != NULL, NULL); g_return_val_if_fail(is_node_list(node), NULL); for (tmp = node->value; tmp != NULL; tmp = tmp->next, index--) { if (index == 0) return tmp->data; } return NULL; }
static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node) { STATUSBAR_CONFIG_REC *bar; GSList *tmp; const char *visible_str; g_return_if_fail(is_node_list(node)); g_return_if_fail(node->key != NULL); bar = statusbar_config_find(group, node->key); if (config_node_get_bool(node, "disabled", FALSE)) { /* disabled, destroy it if it already exists */ if (bar != NULL) statusbar_config_destroy(group, bar); return; } if (bar == NULL) { bar = statusbar_config_create(group, node->key); bar->type = STATUSBAR_TYPE_ROOT; bar->placement = STATUSBAR_BOTTOM; bar->position = 0; } visible_str = config_node_get_str(node, "visible", ""); if (g_ascii_strcasecmp(visible_str, "active") == 0) bar->visible = STATUSBAR_VISIBLE_ACTIVE; else if (g_ascii_strcasecmp(visible_str, "inactive") == 0) bar->visible = STATUSBAR_VISIBLE_INACTIVE; else bar->visible = STATUSBAR_VISIBLE_ALWAYS; if (g_ascii_strcasecmp(config_node_get_str(node, "type", ""), "window") == 0) bar->type = STATUSBAR_TYPE_WINDOW; if (g_ascii_strcasecmp(config_node_get_str(node, "placement", ""), "top") == 0) bar->placement = STATUSBAR_TOP; bar->position = config_node_get_int(node, "position", 0); node = iconfig_node_section(node, "items", -1); if (node != NULL) { /* we're overriding the items - destroy the old */ while (bar->items != NULL) statusbar_config_item_destroy(bar, bar->items->data); tmp = config_node_first(node->value); for (; tmp != NULL; tmp = config_node_next(tmp)) statusbar_read_item(bar, tmp->data); } }
CONFIG_NODE *config_node_find(CONFIG_NODE *node, const char *key) { GSList *tmp; g_return_val_if_fail(node != NULL, NULL); g_return_val_if_fail(key != NULL, NULL); g_return_val_if_fail(is_node_list(node), NULL); for (tmp = node->value; tmp != NULL; tmp = tmp->next) { CONFIG_NODE *node = tmp->data; if (node->key != NULL && g_strcasecmp(node->key, key) == 0) return node; } return NULL; }
CONFIG_NODE *config_node_nth(CONFIG_NODE *node, int index) { GSList *tmp; g_return_val_if_fail(node != NULL, NULL); g_return_val_if_fail(is_node_list(node), NULL); for (tmp = node->value; tmp != NULL; tmp = tmp->next) { CONFIG_NODE *node = tmp->data; if (node->type != NODE_TYPE_COMMENT) { if (index == 0) return node; index--; } } return NULL; }
void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) { GSList *tmp; g_return_if_fail(info != NULL); g_return_if_fail(node != NULL); g_return_if_fail(is_node_list(node)); /* remove all old keys */ while (info->keys != NULL) key_configure_destroy(info->keys->data); /* add the new keys */ for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->key != NULL) key_configure_create(info->id, node->key, node->value); } }
static void statusbar_read_group(CONFIG_NODE *node) { STATUSBAR_GROUP_REC *group; GSList *tmp; int i; g_return_if_fail(is_node_list(node)); group = statusbar_group_find(node->key); if (group == NULL) { group = statusbar_group_create(node->key); if (active_statusbar_group == NULL) active_statusbar_group = group; } for (tmp = config_node_first(node->value), i = 0; tmp != NULL; tmp = config_node_next(tmp), i++) { CONFIG_NODE *value = tmp->data; skip_corrupt_config(node, value, i, "statusbar"); statusbar_read(group, value); } }
void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) { GSList *tmp; char *data, *key; g_return_if_fail(info != NULL); g_return_if_fail(node != NULL); g_return_if_fail(is_node_list(node)); /* remove all old keys */ while (info->keys != NULL) key_configure_remove(((KEY_REC *) info->keys->data)->key); /* add the new keys */ for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; data = config_node_get_str(node->value, "data", NULL); key = config_node_get_str(node->value, "key", NULL); if (key != NULL) key_configure_add(info->id, data, key); } }
/* find the section from node - if not found create it unless new_type is -1. you can also specify in new_type if it's NODE_TYPE_LIST or NODE_TYPE_BLOCK */ CONFIG_NODE *config_node_section(CONFIG_NODE *parent, const char *key, int new_type) { CONFIG_NODE *node; g_return_val_if_fail(parent != NULL, NULL); g_return_val_if_fail(is_node_list(parent), NULL); node = key == NULL ? NULL : config_node_find(parent, key); if (node != NULL) { g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL); return node; } if (new_type == -1) return NULL; node = g_new0(CONFIG_NODE, 1); parent->value = g_slist_append(parent->value, node); node->type = new_type; node->key = key == NULL ? NULL : g_strdup(key); return node; }