static GNode * xmms_magic_add_node (GNode *tree, const gchar *s, GNode *prev_node) { xmms_magic_entry_t *entry; gpointer *data = tree->data; guint indent = 0, prev_indent; g_assert (s); XMMS_DBG ("adding magic spec to tree '%s'", (gchar *) data[0]); /* indent level is number of leading '>' characters */ while (*s == '>') { indent++; s++; } entry = parse_entry (s); if (!entry) { XMMS_DBG ("cannot parse magic entry"); return NULL; } if (!indent) { return g_node_append_data (tree, entry); } if (!prev_node) { XMMS_DBG ("invalid indent level"); xmms_magic_entry_free (entry); return NULL; } prev_indent = g_node_depth (prev_node) - 2; if (indent > prev_indent) { /* larger jumps are invalid */ if (indent != prev_indent + 1) { XMMS_DBG ("invalid indent level"); xmms_magic_entry_free (entry); return NULL; } return g_node_append_data (prev_node, entry); } else { while (indent < prev_indent) { prev_indent--; prev_node = prev_node->parent; } return g_node_insert_after (prev_node->parent, prev_node, g_node_new (entry)); } }
/** * clutter_score_append: * @score: a #ClutterScore * @parent: a #ClutterTimeline in the score, or %NULL * @timeline: a #ClutterTimeline * * Appends a timeline to another one existing in the score; the newly * appended timeline will be started when @parent is complete. * * If @parent is %NULL, the new #ClutterTimeline will be started when * clutter_score_start() is called. * * #ClutterScore will take a reference on @timeline. * * Return value: the id of the #ClutterTimeline inside the score, or * 0 on failure. The returned id can be used with clutter_score_remove() * or clutter_score_get_timeline(). * * Since: 0.6 */ gulong clutter_score_append (ClutterScore *score, ClutterTimeline *parent, ClutterTimeline *timeline) { ClutterScorePrivate *priv; ClutterScoreEntry *entry; g_return_val_if_fail (CLUTTER_IS_SCORE (score), 0); g_return_val_if_fail (parent == NULL || CLUTTER_IS_TIMELINE (parent), 0); g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0); priv = score->priv; if (!parent) { entry = g_slice_new (ClutterScoreEntry); entry->timeline = g_object_ref (timeline); entry->parent = NULL; entry->id = priv->last_id; entry->marker = NULL; entry->marker_id = 0; entry->complete_id = 0; entry->score = score; entry->node = g_node_append_data (priv->root, entry); } else { GNode *node; node = find_entry_by_timeline (score, parent); if (G_UNLIKELY (!node)) { g_warning ("Unable to find the parent timeline inside the score."); return 0; } entry = g_slice_new (ClutterScoreEntry); entry->timeline = g_object_ref (timeline); entry->parent = parent; entry->id = priv->last_id; entry->marker = NULL; entry->marker_id = 0; entry->complete_id = 0; entry->score = score; entry->node = g_node_append_data (node, entry); } priv->last_id += 1; return entry->id; }
static void connect_downlink(BOTNET_REC *botnet, int handle, IPADDR *ip, const char *host) { BOT_DOWNLINK_REC *downlink; BOT_REC *bot; g_return_if_fail(botnet != NULL); /* identify the bot who's trying to connect.. */ downlink = bot_downlink_find(botnet, ip, host); if (downlink == NULL || downlink->password == NULL) { /* unknown bot, close connection / bot didn't have password, don't let it connect to us */ net_disconnect(handle); return; } bot = g_new0(BOT_REC, 1); bot->botnet = botnet; bot->link = downlink; g_node_append_data(botnet->bots, bot); /* connected.. */ bot->handle = handle; bot->read_tag = g_input_add(handle, G_INPUT_READ, (GInputFunction) sig_bot_read, bot); }
static FakeNode * add_fake_node (GnomeVFSURI *uri, gboolean directory) { GnomeVFSURI *parent_uri; FakeNode *parent_file; const gchar *path, *name; FakeNode *file; parent_uri = gnome_vfs_uri_get_parent (uri); parent_file = get_fake_node_from_uri (parent_uri); if (!parent_file) { return NULL; } path = gnome_vfs_uri_get_path (uri); name = strrchr (path, '/') + 1; g_print ("ADD FAKE: %s, dir: %d\n", name, directory); file = fake_node_new (name, NULL); file->gnode = g_node_append_data (parent_file->gnode, file); file->directory = directory; print_tree (root, 0); return file; }
static GNode *xml_build_tree(XMLFile *file, GNode *parent, guint level) { GNode *node = NULL; XMLNode *xmlnode; XMLTag *tag; while (xml_parse_next_tag(file) == 0) { if (file->level < level) break; if (file->level == level) { g_warning("xml_build_tree(): Parse error in %s", file->path); break; } tag = xml_get_current_tag(file); if (!tag) break; xmlnode = xml_node_new(xml_copy_tag(tag), NULL); xmlnode->element = xml_get_element(file); if (!parent) node = g_node_new(xmlnode); else node = g_node_append_data(parent, xmlnode); xml_build_tree(file, node, file->level); if (file->level == 0) break; } return node; }
static BOT_REC *bot_add(BOTNET_REC *botnet, const char *nick, const char *parent) { GNode *node; BOT_REC *rec; g_return_val_if_fail(botnet != NULL, NULL); g_return_val_if_fail(nick != NULL, NULL); node = bot_find_nick(botnet, nick); if (node != NULL) return node->data; node = bot_find_nick(botnet, parent); if (node == NULL) return NULL; rec = g_new0(BOT_REC, 1); rec->botnet = botnet; rec->nick = g_strdup(nick); rec->handle = -1; rec->read_tag = -1; rec->connected = TRUE; g_node_append_data(node, rec); return rec; }
static void sig_botnet_connected(int handle, BOT_UPLINK_REC *uplink) { BOTNET_REC *botnet; BOT_REC *bot; g_return_if_fail(uplink != NULL); botnet = uplink->botnet; if (handle == -1) { /* error, try another bot */ botnet_connect(botnet); return; } /* connected to bot */ bot = g_new0(BOT_REC, 1); bot->botnet = botnet; bot->link = uplink; bot->uplink = TRUE; bot->handle = handle; bot->read_tag = g_input_add(handle, G_INPUT_READ, (GInputFunction) sig_bot_read, bot); botnet->uplink = bot; g_node_append_data(botnet->bots, bot); /* send nick/pass */ bot_send_cmdv(bot, "PASS %s", uplink->password); bot_send_cmdv(bot, "NICK %s", botnet->nick); }
static GNode * mount_add_hierarchy (GNode *root, const gchar *uuid, const gchar *mount_point, gboolean removable, gboolean optical) { MountInfo *info; GNode *node; gchar *mp; mp = mount_point_normalize (mount_point); node = mount_node_find (root, mp); if (!node) { node = root; } info = g_slice_new (MountInfo); info->mount_point = mp; info->uuid = g_strdup (uuid); info->removable = removable; info->optical = optical; return g_node_append_data (node, info); }
/** * clutter_score_append_at_marker: * @score: a #ClutterScore * @parent: the parent #ClutterTimeline * @marker_name: the name of the marker to use * @timeline: the #ClutterTimeline to append * * Appends @timeline at the given @marker_name on the @parent * #ClutterTimeline. * * If you want to append @timeline at the end of @parent, use * clutter_score_append(). * * The #ClutterScore will take a reference on @timeline. * * Return value: the id of the #ClutterTimeline inside the score, or * 0 on failure. The returned id can be used with clutter_score_remove() * or clutter_score_get_timeline(). * * Since: 0.8 * Deprecated: 1.8 */ gulong clutter_score_append_at_marker (ClutterScore *score, ClutterTimeline *parent, const gchar *marker_name, ClutterTimeline *timeline) { ClutterScorePrivate *priv; GNode *node; ClutterScoreEntry *entry; gchar *marker_reached_signal; g_return_val_if_fail (CLUTTER_IS_SCORE (score), 0); g_return_val_if_fail (CLUTTER_IS_TIMELINE (parent), 0); g_return_val_if_fail (marker_name != NULL, 0); g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0); if (!clutter_timeline_has_marker (parent, marker_name)) { g_warning ("The parent timeline has no marker '%s'", marker_name); return 0; } priv = score->priv; node = find_entry_by_timeline (score, parent); if (G_UNLIKELY (!node)) { g_warning ("Unable to find the parent timeline inside the score."); return 0; } entry = g_slice_new (ClutterScoreEntry); entry->timeline = g_object_ref (timeline); entry->parent = parent; entry->marker = g_strdup (marker_name); entry->id = priv->last_id; entry->score = score; entry->complete_id = 0; marker_reached_signal = g_strdup_printf ("marker-reached::%s", marker_name); entry->marker_id = g_signal_connect (entry->parent, marker_reached_signal, G_CALLBACK (on_timeline_marker), entry); entry->node = g_node_append_data (node, entry); g_free (marker_reached_signal); priv->last_id += 1; return entry->id; }
void core_tree_building_function(struct site_file *a_file, GNode * tree) { gchar **comps; gchar *leaf; int i = 0; GNode *branch = NULL; struct site_node_data *leaf_node = g_malloc0(sizeof(struct site_node_data)); /* Tokenize the directory name */ NE_DEBUG(DEBUG_GNOME, "Componentizing %s.\n", file_name(a_file)); comps = g_strsplit(file_name(a_file), "/", -1); leaf = (char *) base_name(file_name(a_file)); /* Rather than chopping off the filename when we tokenize the * directory, it's easier to just ignore the last element of * the resulting array, thus. */ branch = tree; while (comps[i + 1] != NULL) { char *component = comps[i]; GNode *tmp2; for (tmp2 = g_node_first_child(branch); tmp2; tmp2 = tmp2->next) { /* Get the name from the GNode we're looking at. */ char *tmp_name; tmp_name = ((struct site_node_data *) tmp2->data)->name; /* Check if it's the one we're looking for */ NE_DEBUG(DEBUG_GNOME, "Comparing %s with %s.\n", component, tmp_name); if (strcmp(component, tmp_name) == 0) { branch = tmp2; break; } } if (!branch) { NE_DEBUG(DEBUG_GNOME, "Branch became NULL. Oh dear.\n"); break; } i++; } /* Initialise a new data struct, and make it a child of whatever * branch is pointing to. */ leaf_node->name = leaf; leaf_node->file = a_file; g_node_append_data(branch, leaf_node); }
/** * gusb_cmd_show: **/ static gboolean gusb_cmd_show (GUsbCmdPrivate *priv, gchar **values, GError **error) { GNode *n; GNode *node; guint i; GUsbDevice *device; GUsbDevice *parent; GPtrArray *devices = NULL; /* sort */ devices = g_usb_context_get_devices (priv->usb_ctx); g_ptr_array_sort (devices, gusb_devices_sort_by_platform_id_cb); /* make a tree of the devices */ node = g_node_new (NULL); for (i = 0; i < devices->len; i++) { device = g_ptr_array_index (devices, i); parent = g_usb_device_get_parent (device); if (parent == NULL) { g_node_append_data (node, device); continue; } n = g_node_find (node, G_PRE_ORDER, G_TRAVERSE_ALL, parent); if (n == NULL) { g_set_error (error, 1, 0, "no parent node for %s", g_usb_device_get_platform_id (device)); return FALSE; } g_node_append_data (n, device); } g_ptr_array_unref (devices); g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, moo_cb, priv); return TRUE; }
static void init_fake_tree () { FakeNode *file; GNode *documents; /* Create a fake directory structure. */ file = fake_node_new ("<root>", NULL); root = g_node_new (file); file->gnode = root; file->directory = TRUE; file = fake_node_new ("documents", NULL); documents = g_node_append_data (root, file); file->gnode = documents; file->directory = TRUE; file = fake_node_new ("test.txt", "Test file\n"); file->gnode = g_node_append_data (root, file); file = fake_node_new ("todo.txt", "Buy milk\nWash dishes\n"); file->gnode = g_node_append_data (documents, file); }
void url_router_add_handler (UrlRouter *router, const gchar *signature, UrlRouterHandler handler, gpointer user_data) { UrlNodeData *data; gchar **parts; GNode *parent = NULL; GNode *node; guint i; g_return_if_fail(router); g_return_if_fail(signature); g_return_if_fail(*signature == '/'); g_return_if_fail(handler); parent = (GNode *)router; parts = g_strsplit(signature, "/", 0); for (i = 1; parts[i]; i++) { for (node = parent->children; node; node = node->next) { data = node->data; if (!g_strcmp0(data->key, parts[i])) { parent = node; break; } else if ((*data->key == ':') && (*(parts[i]) == ':')) { g_warning("Wildcard params starting with : must match names!"); parent = node; break; } } if (!node) { data = url_node_data_new(parts[i], *(parts[i]) == ':', (!parts[i+1]) ? handler : NULL, (!parts[i+1]) ? user_data : NULL); parent = g_node_append_data(parent, data); } } g_strfreev(parts); }
static void append_row (GNode * node, GList * columns) { GladeModelData *data; GladeColumnType *column; GNode *row; GList *list; g_assert (node && columns); row = g_node_new (NULL); g_node_append (node, row); for (list = columns; list; list = list->next) { column = list->data; data = glade_model_data_new (g_type_from_name (column->type_name), column->column_name); g_node_append_data (row, data); } }
static void as_node_start_element_cb (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error) { AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data; AsNodeData *data; AsNode *current; gchar *tmp; guint i; /* create the new node data */ data = g_slice_new0 (AsNodeData); as_node_data_set_name (data, element_name, AS_NODE_INSERT_FLAG_NONE); for (i = 0; attribute_names[i] != NULL; i++) { as_node_attr_insert (data, attribute_names[i], attribute_values[i]); } /* add the node to the DOM */ current = g_node_append_data (helper->current, data); /* transfer the ownership of the comment to the new child */ tmp = as_node_take_attribute (helper->current, "@comment-tmp"); if (tmp != NULL) { as_node_add_attribute (current, "@comment", tmp); g_free (tmp); } /* the child is now the node to be processed */ helper->current = current; }
static void ltable_insert(LTable* lt, const gchar* where, Listener* l) { gchar** dirnames; guint i; GNode* cur; GNode* found = NULL; LTableEntry* lte; const gchar* noroot_where = where + 1; g_return_if_fail(mateconf_valid_key(where, NULL)); if (lt->tree == NULL) { lte = ltable_entry_new(NULL, 0); lt->tree = g_node_new(lte); lte = NULL; /* paranoia */ } /* Add to the tree */ dirnames = g_strsplit(noroot_where, "/", -1); cur = lt->tree; i = 0; while (dirnames[i]) { LTableEntry* ne; GNode* across; /* Find this dirname on this level, or add it. */ g_assert (cur != NULL); found = NULL; across = cur->children; while (across != NULL) { int cmp; lte = across->data; cmp = strcmp(lte->name, dirnames[i]); if (cmp == 0) { found = across; break; } else if (cmp > 0) { /* Past it */ break; } else { across = g_node_next_sibling(across); } } if (found == NULL) { ne = ltable_entry_new(dirnames, i); if (across != NULL) /* Across is at the one past */ found = g_node_insert_data_before(cur, across, ne); else /* Never went past, append - could speed this up by saving last visited */ found = g_node_append_data(cur, ne); } g_assert(found != NULL); cur = found; ++i; } /* cur is still the root node ("/") if where was "/" since nothing was returned from g_strsplit */ lte = cur->data; lte->listeners = g_list_prepend(lte->listeners, l); g_strfreev(dirnames); /* Add tree node to the flat table */ g_ptr_array_set_size(lt->listeners, MAX(CNXN_ID_INDEX(lt->next_cnxn), CNXN_ID_INDEX(l->cnxn))); g_ptr_array_index(lt->listeners, CNXN_ID_INDEX(l->cnxn)) = cur; lt->active_listeners += 1; #ifdef DEBUG_LISTENERS g_print ("Added %u at %s, spewing:\n", l->cnxn, where); ltable_spew(lt); #endif }
static void g_node_test (void) { GNode *root; GNode *node; GNode *node_B; GNode *node_D; GNode *node_F; GNode *node_G; GNode *node_J; guint i; gchar *tstring; failed = FALSE; root = g_node_new (C2P ('A')); TEST (NULL, g_node_depth (root) == 1 && g_node_max_height (root) == 1); node_B = g_node_new (C2P ('B')); g_node_append (root, node_B); TEST (NULL, root->children == node_B); g_node_append_data (node_B, C2P ('E')); g_node_prepend_data (node_B, C2P ('C')); node_D = g_node_new (C2P ('D')); g_node_insert (node_B, 1, node_D); node_F = g_node_new (C2P ('F')); g_node_append (root, node_F); TEST (NULL, root->children->next == node_F); node_G = g_node_new (C2P ('G')); g_node_append (node_F, node_G); node_J = g_node_new (C2P ('J')); g_node_prepend (node_G, node_J); g_node_insert (node_G, 42, g_node_new (C2P ('K'))); g_node_insert_data (node_G, 0, C2P ('H')); g_node_insert (node_G, 1, g_node_new (C2P ('I'))); TEST (NULL, g_node_depth (root) == 1); TEST (NULL, g_node_max_height (root) == 4); TEST (NULL, g_node_depth (node_G->children->next) == 4); TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7); TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4); TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 11); TEST (NULL, g_node_max_height (node_F) == 3); TEST (NULL, g_node_n_children (node_G) == 4); TEST (NULL, g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F); TEST (NULL, g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL); TEST (NULL, g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J); for (i = 0; i < g_node_n_children (node_B); i++) { node = g_node_nth_child (node_B, i); TEST (NULL, P2C (node->data) == ('C' + i)); } for (i = 0; i < g_node_n_children (node_G); i++) TEST (NULL, g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i); /* we have built: A * / \ * B F * / | \ \ * C D E G * / /\ \ * H I J K * * for in-order traversal, 'G' is considered to be the "left" * child of 'F', which will cause 'F' to be the last node visited. */ tstring = NULL; g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "ABCDEFGHIJK") == 0); g_free (tstring); tstring = NULL; g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "CDEBHIJKGFA") == 0); g_free (tstring); tstring = NULL; g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "CBDEAHGIJKF") == 0); g_free (tstring); tstring = NULL; g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "ABFCDEGHIJK") == 0); g_free (tstring); tstring = NULL; g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "CDEHIJK") == 0); g_free (tstring); tstring = NULL; g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "ABFG") == 0); g_free (tstring); tstring = NULL; g_node_reverse_children (node_B); g_node_reverse_children (node_G); g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "ABFEDCGKJIH") == 0); g_free (tstring); tstring = NULL; g_node_append (node_D, g_node_new (C2P ('L'))); g_node_append (node_D, g_node_new (C2P ('M'))); g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring); TEST (tstring, strcmp (tstring, "ABFEDCGLMKJIH") == 0); g_free (tstring); tstring = NULL; g_node_destroy (root); /* allocation tests */ root = g_node_new (NULL); node = root; for (i = 0; i < 2048; i++) { g_node_append (node, g_node_new (NULL)); if ((i%5) == 4) node = node->children->next; } TEST (NULL, g_node_max_height (root) > 100); TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048); g_node_destroy (root); if (failed) exit(1); }
static void remmina_file_manager_add_group(GNode* node, const gchar* group) { gint cmp; gchar* p1; gchar* p2; GNode* child; gboolean found; RemminaGroupData* data; if (group == NULL || group[0] == '\0') return; p1 = g_strdup(group); p2 = strchr(p1, '/'); if (p2) *p2++ = '\0'; found = FALSE; for (child = g_node_first_child(node); child; child = g_node_next_sibling(child)) { cmp = g_strcmp0(((RemminaGroupData*) child->data)->name, p1); if (cmp == 0) { found = TRUE; break; } if (cmp > 0) break; } if (!found) { data = g_new0(RemminaGroupData, 1); data->name = p1; if (node->data) { data->group = g_strdup_printf("%s/%s", ((RemminaGroupData*) node->data)->group, p1); } else { data->group = g_strdup(p1); } if (child) { child = g_node_insert_data_before(node, child, data); } else { child = g_node_append_data(node, data); } } remmina_file_manager_add_group(child, p2); if (found) { g_free(p1); } }
void se_modemap_insert_keybinding_str( se_modemap *map, const char* keys_rep, se_key_command_t cmd ) { g_assert( map && keys_rep && cmd ); se_key_seq keyseq = se_key_seq_from_string( keys_rep ); if ( keyseq.len <= 0 ) { se_warn( "bad key seq" ); return; } if ( se_modemap_keybinding_exists(map, keyseq) ) { /* se_msg("remap an existed keybinding" ); */ } GNode *node = map->root; int need_create_node = FALSE; // trace from which level we need to create nodes for (int i = 0; i < keyseq.len; ++i) { se_key key = keyseq.keys[i]; /* se_debug( "current key %s", se_key_to_string(key) ); */ if ( !need_create_node ) { GNode *key_node = se_modemap_search_next_level(map, node, key); if ( !key_node ) { need_create_node = TRUE; --i; /* se_debug( "set need_create_node and i = %d", i ); */ continue; } /* se_debug( "key %s exists at level %d", se_key_to_string(key), */ /* g_node_depth(node) ); */ node = key_node; se_modemap_data *data = key_node->data; g_assert( data ); g_assert( se_key_is_equal(key, data->key) ); if ( i+1 == keyseq.len ) { // bind to a cmd if ( !G_NODE_IS_LEAF(key_node) ) { // delete sub tree /* se_debug( "delete sub tree" ); */ se_delete_subtree( key_node ); } g_assert( G_NODE_IS_LEAF(key_node) ); data->cmd = cmd; /* se_debug( "rebind key %s", se_key_to_string(key) ); */ } else { if ( G_NODE_IS_LEAF(key_node) ) { g_assert( data->cmd ); data->cmd = NULL; need_create_node = TRUE; // create nodes from next level /* se_debug( "set need_create_node, reset key %s to Null", */ /* se_key_to_string(key) ); */ } else { g_assert( data->cmd == NULL ); } } } else { se_modemap_data *data = g_malloc0( sizeof(se_modemap_data) ); data->key = key; GNode *key_node = g_node_append_data( node, data ); if ( i+1 == keyseq.len ) { // bind to a cmd /* se_debug( "leaf node (level %d) of key %s: bind cmd", */ /* g_node_depth(key_node), se_key_to_string(data->key) ); */ data->cmd = cmd; } node = key_node; } } }
static bool cloud_config_parse(yaml_parser_t *parser, GNode *node, int state) { GNode *last_leaf = node; yaml_event_t event; bool finished = 0; while (!finished) { if (!yaml_parser_parse(parser, &event)) { LOG("An error occurred while the yaml file was parsed.\n"); return false; } switch (event.type) { case YAML_SCALAR_EVENT: if (state & SEQ) { last_leaf = g_node_append(node, g_node_new(g_strdup((gchar*) event.data.scalar.value))); } else if (state & VAL) { g_node_append_data(last_leaf, g_strdup((gchar*) event.data.scalar.value)); state &= MAP | SEQ; } else { last_leaf = g_node_append(node, g_node_new(g_strdup((gchar*) event.data.scalar.value))); state |= VAL; } break; case YAML_SEQUENCE_START_EVENT: /* remove VAL bit if it's set */ if (state & MAP) state = MAP; if (state & SEQ) { last_leaf = g_node_append(node, g_node_new(NULL)); } else { last_leaf = g_node_append(last_leaf, g_node_new(NULL)); } if (!cloud_config_parse(parser, last_leaf, SEQ)) { return false; } last_leaf = last_leaf->parent; break; case YAML_SEQUENCE_END_EVENT: finished = true; break; case YAML_MAPPING_START_EVENT: last_leaf = g_node_append(node, g_node_new(NULL)); if (!cloud_config_parse(parser, last_leaf, MAP)) { return false; } last_leaf = last_leaf->parent; break; case YAML_MAPPING_END_EVENT: last_leaf = last_leaf->parent; finished = true; break; case YAML_STREAM_END_EVENT: finished = true; break; case YAML_NO_TOKEN: LOG("Unexpectedly reached end of YAML input!"); finished = true; break; default: /* Ignore these for now */ break; } if (!finished) { yaml_event_delete(&event); } } return true; }