void bot_destroy(BOT_REC *bot) { GNode *node; g_return_if_fail(bot != NULL); node = g_node_find(bot->botnet->bots, 0, G_TRAVERSE_ALL, bot); if (node != NULL) { if (!bot->disconnect) bot_mark_disconnects(node); } bot_disconnect(bot); if (node != NULL) { while (node->children != NULL) bot_destroy(node->children->data); g_node_destroy(node); } if (bot->botnet->uplink == bot) bot->botnet->uplink = NULL; if (bot->botnet->master == bot) bot->botnet->master = NULL; while (bot->ircnets != NULL) bot_ircnet_destroy(bot, bot->ircnets->data); line_split_free(bot->buffer); g_free_not_null(bot->nick); g_free(bot); }
/* send botnet links to specified bot */ static void botnet_send_links(BOT_REC *bot, int downlinks) { GNode *node; if (!downlinks) { /* send uplinks */ if (bot->botnet->uplink == NULL) return; node = g_node_find(bot->botnet->bots, G_IN_ORDER, G_TRAVERSE_ALL, bot->botnet->uplink); if (node == NULL) return; g_node_traverse(node, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) botnet_send_botinfo, bot); return; } /* send downlinks = all non-uplink nodes */ for (node = bot->botnet->bots->children; node != NULL; node = node->next) { BOT_REC *rec = node->data; if (rec == bot || rec->uplink || !rec->connected) continue; g_node_traverse(node, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) botnet_send_botinfo, bot); } }
/* * Mark children as invisible, if needed. */ static void gopt_set_children_visible(struct gopt_job_view *gjv, struct fio_option *parent, gboolean visible) { GNode *child, *node; if (parent->hide_on_set) visible = !visible; node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent); child = g_node_first_child(node); while (child) { struct fio_option *o = child->data; struct gopt *g = o->gui_data; GtkWidget *widget = g->box; /* * Recurse into child, if it also has children */ if (g_node_n_children(child)) gopt_set_children_visible(gjv, o, visible); gtk_widget_set_sensitive(widget, visible); child = g_node_next_sibling(child); } }
/** * 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; }
void board_eventhandler (BOARD_WIDGET* board, GNode* root) { int ch; int selected_data_index; STOCKINFO* temp; GNode* temp_node; GNode* market; bool flag; int remember_index; int i; activate_board (board); while ((ch = getch ()) != 'q') { switch (ch) { case KEY_UP : scrollup_handler (board); break; case KEY_DOWN : scrolldown_handler (board); break; case KEY_PPAGE : pageup_handler (board); break; case KEY_NPAGE : pagedown_handler (board); break; case KEY_RESIZE : /* clear_board (board); */ resize_handler (board); break; case '\n' : if ((*(int*) (board -> userdata) & 0x000f) == 1) { selected_data_index = board -> firstrow_index + board -> selected_index; temp = (STOCKINFO*) g_ptr_array_index ( board -> dataTable, selected_data_index); if (temp -> depth <= 2) { market = g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAVES, (gpointer) temp); temp_node = g_node_first_child (market); flag = ((STOCKINFO*) (temp_node -> data)) -> IsActivated; open_close_branch (market, !flag); clear_board (board); g_ptr_array_unref (board -> dataTable); board -> dataTable = node_to_array (root, board -> dataTable); remember_index = board -> selected_index; set_rowIndex (board, 0); /*set_rowIndex (board, -1);*/ set_rowIndex (board, remember_index); board -> wndFlag = true; board -> dataFlag = true; update_board (board); } break; } break; case 'o' : option_handler (board); break; } usleep (1000); } inactivate_board (board); }
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); }