Ejemplo n.º 1
0
static void test_getChildInDirectory_DirectoryIsEmpty() {
    before();
    GNode *tree = single_folder(TRUE, TRUE);

// THIS IS THE STRUCTURE:
//
// test-dir (7 children)
// ├─ .apa.png
// ├─ .depa.gif
// ├─ bepa.png
// ├─ cepa.jpg
// ├─ epa.png
// ├─┬dir_one (3 children)
// │ ├─ .three.png
// │ ├─ two.jpg
// │ └─┬.secrets (1 children)
// │   └─ img.jpg
// └─┬dir_two (7 children)
//   ├─ apa.png
//   ├─ bepa.png
//   ├─ cepa.png
//   ├─┬sub_dir_four (2 children)
//   │ ├──subsub (0 children)
//   │ └──subsub2 (0 children)
//   ├─┬sub_dir_one (3 children)
//   │ ├─ img0.png
//   │ ├─ img1.png
//   │ └─ img2.png
//   ├──sub_dir_three (0 children)
//   └─┬sub_dir_two (3 children)
//     ├─ img0.png
//     ├─ img1.png
//     ├─ img2.png
//     └─ img3.png

    char *path0 = get_absolute_path(testdir_path, "/dir_two/sub_dir_four/subsub");
    char *path1 = get_absolute_path(testdir_path, "/dir_two/sub_dir_four/subsub/apa.jpg");

    GNode *child = get_root_node(tree);
    child = g_node_last_child(child);
    child = g_node_first_child(child);
    child = g_node_next_sibling(child);
    child = g_node_next_sibling(child);
    child = g_node_next_sibling(child);
    child = g_node_first_child(child);
    assert_child_is_equal("Get child in directory ─ Last child is subsub", child, path0);

    child = get_child_in_directory(child, path1);

    assert_tree_is_null("Get child in directory ─ Directory is empty", child);

    free(path0);
    free(path1);
    free_whole_tree(tree);
    after();
}
Ejemplo n.º 2
0
    static GNode*
find_stat_node(GNode *parent_stat_node, header_field_info *needle_hfinfo)
{
    GNode		*needle_stat_node, *up_parent_stat_node;
    header_field_info	*hfinfo;
    ph_stats_node_t	*stats;

    /* Look down the tree */
    needle_stat_node = g_node_first_child(parent_stat_node);

    while (needle_stat_node) {
        hfinfo = STAT_NODE_HFINFO(needle_stat_node);
        if (hfinfo &&  hfinfo->id == needle_hfinfo->id) {
            return needle_stat_node;
        }
        needle_stat_node = g_node_next_sibling(needle_stat_node);
    }

    /* Look up the tree */
    up_parent_stat_node = parent_stat_node;
    while (up_parent_stat_node && up_parent_stat_node->parent)
    {
        needle_stat_node = g_node_first_child(up_parent_stat_node->parent);
        while (needle_stat_node) {
            hfinfo = STAT_NODE_HFINFO(needle_stat_node);
            if (hfinfo &&  hfinfo->id == needle_hfinfo->id) {
                return needle_stat_node;
            }
            needle_stat_node = g_node_next_sibling(needle_stat_node);
        }

        up_parent_stat_node = up_parent_stat_node->parent;
    }

    /* None found. Create one. */
    stats = g_new(ph_stats_node_t, 1);

    /* Intialize counters */
    stats->hfinfo = needle_hfinfo;
    stats->num_pkts_total = 0;
    stats->num_pkts_last = 0;
    stats->num_bytes_total = 0;
    stats->num_bytes_last = 0;

    needle_stat_node = g_node_new(stats);
    g_node_append(parent_stat_node, needle_stat_node);
    return needle_stat_node;
}
Ejemplo n.º 3
0
static struct lua_cmd_entry *lua_cmd_find(gchar **argv, gint *offp)
{
	gchar **argp;
	GNode *node;

	if (main_tree == NULL)
		return NULL;

	node = main_tree;
	argp = argv;
	for (;;) {
		node = g_node_first_child(node);
		if (G_NODE_IS_LEAF(node)) {
			struct lua_cmd_entry *entry;

			entry = (struct lua_cmd_entry *) node->data;
			*offp = argp - argv - 1;
			return entry;
		}

		if (*argp == NULL)
			return NULL;

		for (; node != NULL; node = g_node_next_sibling(node))
			if (! strcmp(*argp, node->data))
				break;

		if (node == NULL)
			return NULL;
		argp++;
	}
}
Ejemplo n.º 4
0
void gnode_to_gui(GNode * root,
		  GtkCTreeNode * a_node)
{

    GNode *tmp;
    GtkCTreeNode *new_node;

    NE_DEBUG(DEBUG_GNOME, "Building GUI tree from GNode hierarchy... \n");

    if (!root)
	return;

    tmp = g_node_first_child(root);

    while (tmp) {
	new_node = add_file(name(tmp),
			    file(tmp),
			    a_node);

	gnode_to_gui(tmp, new_node);
	tmp = g_node_next_sibling(tmp);
    }

    gnode_to_gui(tmp, a_node);

}
Ejemplo n.º 5
0
void mk_key_value_write_lines(const gchar* prefix, 
                           const GNode* root,
                           GIOChannel* chan)
{
    GNode* n = g_node_first_child(root);
    for(; n != NULL; n = g_node_next_sibling(n)) {
        MkNodeInfo* info = (MkNodeInfo*)(n->data);

        gchar* prefix2;
        if (prefix != NULL) {
            prefix2 = g_strconcat(prefix, ".", info->name, NULL);
        } else {
            prefix2 = g_strdup(info->name);
        }

        if (info->name != NULL) {
            if (prefix != NULL) {
                g_io_channel_write_chars(chan, prefix, -1, NULL, NULL);
                g_io_channel_write_chars(chan, ".", -1, NULL, NULL);
            }
            g_io_channel_write_chars(chan, info->name, -1, NULL, NULL);
            g_io_channel_write_chars(chan, "=", -1, NULL, NULL);

            if (info->value != NULL)
                g_io_channel_write_chars(chan, info->value, -1, NULL, NULL);

            g_io_channel_write_chars(chan, "\n", -1, NULL, NULL);
        }

        mk_key_value_write_lines(prefix2, n, chan);
        g_free(prefix2);
    }    
}
Ejemplo n.º 6
0
/*
 * 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);
	}
}
/**
 * get_next_sibling_node(GNode * cur_node)
 * @brief Gets next sibling node, or wraps around if NULL
 * @param cur_node
 * @return GNode of sibling next, or wrapped around
 */
GNode *get_next_sibling_node(GNode * cur_node)
{
	GNode *tmp_node = NULL;
	if ((tmp_node = g_node_next_sibling(cur_node)) == NULL) {
		return g_node_first_sibling(cur_node);
	}
	return tmp_node;
}
Ejemplo n.º 8
0
GNode *search_node_by_name(GNode *directory, char *name)
{
	GNode *file_ptr;

	for (file_ptr = g_node_first_child(directory); file_ptr != NULL;
			file_ptr = g_node_next_sibling(file_ptr)) {
		if (!strcmp(FILE(file_ptr)->name, name))
			return file_ptr;
	}

	return NULL;
}
Ejemplo n.º 9
0
static void
print_child_nodes (GNode *node,
                   gint   depth)
{
  GNode *child;

  for (child = g_node_first_child (node); child != NULL; child = g_node_next_sibling (child))
    {
      g_node_traverse (child, G_PRE_ORDER, G_TRAVERSE_ALL, 1,
                       (GNodeTraverseFunc) print_node, GINT_TO_POINTER (depth+2));
    }
}
Ejemplo n.º 10
0
static void ls_print_tree(GNode *node, gboolean deep)
{
	__extension__
	void node_walk(GNode *node, guint off, gboolean deep)
	{
		node = g_node_first_child(node);
		for (; node != NULL; node = g_node_next_sibling(node)) {
			if (G_NODE_IS_LEAF(node))
				continue;

			g_print("%*s%s\n", off, "", (gchar *) node->data);

			if (deep) node_walk(node, off + 2, deep);
		}
	}
Ejemplo n.º 11
0
GNode *node_find_child(GNode* node, const gchar* data) {
	GNode* child;
	if (! node) {
		return NULL;
	}

	child = g_node_first_child(node);
	while (child) {
		if (g_strcmp0(child->data, data) == 0) {
			return child;
		}
		child = g_node_next_sibling(child);
	}

	return NULL;
}
Ejemplo n.º 12
0
static void
book_tree_populate_tree (DhBookTree *tree)
{
	g_return_if_fail (tree != NULL);
	g_return_if_fail (DH_IS_BOOK_TREE (tree));

	DhBookTreePriv *priv = tree->priv;

	int i = 0;
	GNode *node = g_node_first_child (*priv->link_tree);
	for (; node; node = g_node_next_sibling (node)) {
		book_tree_insert_node (tree, node, NULL);
		i++;
	}
	dbg(2, "n_nodes=%i", i);
}
Ejemplo n.º 13
0
	void dirs_set_size(AGlActor* actor)
	{
		DirectoriesView* view = (DirectoriesView*)actor;

		#define N_ROWS_VISIBLE(A) (agl_actor__height(((AGlActor*)A)) / row_height)
		view->cache.n_rows_visible = N_ROWS_VISIBLE(actor);

		if(!view->cache.n_rows){
			GNode* node = g_node_first_child (samplecat.model->dir_tree);
			for(; node; node = g_node_next_sibling(node)){
				view->cache.n_rows++;
			}
			agl_actor__invalidate(actor);
		}

		actor->region.y2 = MIN(actor->region.y2, actor->region.y1 + (view->cache.n_rows + 1) * row_height);
	}
Ejemplo n.º 14
0
static GNode* se_modemap_search_next_level(se_modemap *map, GNode *node, se_key key)
{
    g_assert( map && node );
   /* se_debug( "search for %s", se_key_to_string(key) ); */
    
    GNode *np = g_node_first_child ( node );
    while ( np ) {
        se_modemap_data *data = np->data;
        if ( se_key_is_equal(data->key, key) ) {
           /* se_debug( "find %s at level %d", se_key_to_string(key), g_node_depth(np) ); */
            return np;
        }
        np = g_node_next_sibling( np );
    }

    return NULL;
}
Ejemplo n.º 15
0
void dump_g_node(GNode * tree)
{

    struct site_node_data *tmp;
    GNode *tmp2 = tree;
    GNode *tmp3;

    while (tmp2) {
	tmp = tmp2->data;
	printf("%s has siblings:\n", tmp->name);
	tmp3 = tmp2;
	for (; g_node_next_sibling(tmp3); tmp3 = tmp3->next) {
	    printf(" %s ", ((struct site_node_data *) tmp3->data)->name);
	}
	printf("\n");
	tmp2 = g_node_first_child(tmp2);
    }
}
/**
 * recursive_menu_dump(GNode * node, uint8_t level)
 */
static void recursive_menu_dump(GNode * node, uint8_t level)
{
	uint8_t level_tmp = level;
	if (node->children) {
		GNode *tmp = g_node_first_child(node);
		while (tmp != NULL) {
			dump_menu_item((menu_item_t *) tmp->data, level_tmp++);
			if (tmp->children) {
				recursive_menu_dump(tmp, level_tmp++);
			}
			tmp = g_node_next_sibling(tmp);

		}

	} else {
		dump_menu_item((menu_item_t *) node->data, level);
	}
}
Ejemplo n.º 17
0
void remmina_file_manager_free_group_tree(GNode* node)
{
	RemminaGroupData* data;
	GNode* child;

	if (!node)
		return;
	data = (RemminaGroupData*) node->data;
	if (data)
	{
		g_free(data->name);
		g_free(data->group);
		g_free(data);
		node->data = NULL;
	}
	for (child = g_node_first_child(node); child; child = g_node_next_sibling(child))
	{
		remmina_file_manager_free_group_tree(child);
	}
	g_node_unlink(node);
}
Ejemplo n.º 18
0
static void
book_tree_insert_node (DhBookTree *tree, GNode *node, GtkTreeIter *parent_iter)
{
	DhBookTreePriv      *priv;
	GtkTreeIter          iter;
	DhLink              *link;
	GNode               *child;
        
	g_return_if_fail (DH_IS_BOOK_TREE (tree));
	g_return_if_fail (node != NULL);

	priv = tree->priv;
	link = (DhLink *) node->data;
	
	gtk_tree_store_append (priv->store, &iter, parent_iter);

	if (link->type == DH_LINK_TYPE_BOOK) {
		//printf("book_tree_insert_node(): DH_LINK_TYPE_BOOK: %s\n", link->name);
		gtk_tree_store_set (priv->store, &iter, 
				    COL_OPEN_PIXBUF,   priv->pixbufs->pixbuf_opened,
				    COL_CLOSED_PIXBUF, priv->pixbufs->pixbuf_closed,
				    COL_TITLE,         link->name,
				    COL_LINK,          link,
				    -1);
	} else {
		//printf("book_tree_insert_node(): not book. %s %p\n", link->name, link);
		gtk_tree_store_set (priv->store, &iter, 
				    COL_OPEN_PIXBUF,   priv->pixbufs->pixbuf_helpdoc,
				    COL_CLOSED_PIXBUF, priv->pixbufs->pixbuf_helpdoc,
				    COL_TITLE,         link->name,
				    COL_LINK,          link,
				    -1);
	}
	
	for (child = g_node_first_child (node);
	     child;
	     child = g_node_next_sibling (child)) {
		book_tree_insert_node (tree, child, &iter);
	}
}
Ejemplo n.º 19
0
static gboolean remmina_main_load_file_tree_traverse(GNode *node, GtkTreeStore *store, GtkTreeIter *parent)
{
	GtkTreeIter *iter;
	RemminaGroupData *data;
	GNode *child;

	iter = NULL;
	if (node->data)
	{
		data = (RemminaGroupData*) node->data;
		iter = g_new0(GtkTreeIter, 1);
		gtk_tree_store_append(store, iter, parent);
		gtk_tree_store_set(store, iter, PROTOCOL_COLUMN, GTK_STOCK_DIRECTORY, NAME_COLUMN, data->name, GROUP_COLUMN,
				data->group, FILENAME_COLUMN, NULL, -1);
	}
	for (child = g_node_first_child(node); child; child = g_node_next_sibling(child))
	{
		remmina_main_load_file_tree_traverse(child, store, iter);
	}
	g_free(iter);
	return FALSE;
}
Ejemplo n.º 20
0
GNode *cloud_config_find(GNode* node, gchar** path) {
	GNode* child;

	if (!path) {
		if (g_node_depth(node) == 0) {
			return NULL;
		}
		/* reached the end of our search, so return this node as value */
		return g_node_first_child(node);
	}

	child = g_node_first_child(node);
	while (child) {
		if (g_strcmp0(child->data, path[0]) == 0) {
			/* recurse */
			return cloud_config_find(child, (gchar**)path[1]);
		}
		child = g_node_next_sibling(child);
	}

	return NULL;
}
Ejemplo n.º 21
0
AGlActor*
directories_view(WaveformActor* _)
{
	instance_count++;

	_init();

	bool dirs_paint(AGlActor* actor)
	{
		DirectoriesView* view = (DirectoriesView*)actor;

		agl_enable_stencil(0, 0, actor->region.x2, actor->region.y2);

		int i = 0;
		GNode* node = g_node_first_child (samplecat.model->dir_tree);
		for(; node && i < view->cache.n_rows; node = g_node_next_sibling(node)){
			DhLink* link = (DhLink*)node->data;

			if(i == view->selection/* - view->scroll_offset*/){
				agl->shaders.plain->uniform.colour = 0x6677ff77;
				agl_use_program((AGlShader*)agl->shaders.plain);
				agl_rect_((AGlRect){0, i * row_height - 2, agl_actor__width(actor), row_height});
			}

			agl_print(0, i * row_height, 0, 0xffffffff, strlen(link->uri) ? link->uri : link->name);

			gboolean node_open = false;
			if(node_open){
				// recurse children
			}
			i++;
		}

		agl_disable_stencil();

		return true;
	}
Ejemplo n.º 22
0
static char *generator(const char *text, int state)
{
	static GNode *node;
	static int len;
	char *data;

	if (!state) {
		node = g_node_first_child(head_node);
		len = strlen(text);
	}

	if (node == NULL || G_NODE_IS_LEAF(node))
		return NULL;

	while (node != NULL) {
		data = (char *) node->data;
		node = g_node_next_sibling(node);

		if (!strncmp(text, data, len))
			return g_strdup(data);
	}

	return NULL;
}
Ejemplo n.º 23
0
/*!
 * find and call the spec handler for each child of GNode
 *
 * \param [in] root \c GNode
 * \param[in,out] config \ref cc_oci_config.
 * \param spec_handlers Array of \ref spec_handler's.
 *
 * \return \c false if a spec handler fails, else \c true.
 */
gboolean
cc_oci_process_config (GNode *root, struct cc_oci_config *config,
	struct spec_handler **spec_handlers)
{
	GNode* node;

	for (node = g_node_first_child(root); node; node = g_node_next_sibling(node)) {
		if (! node->data) {
			continue;
		}

		if (node->children) {
			if (g_strcmp0 (node->data, "ociVersion") == 0) {
				config->oci.oci_version = g_strdup (node->children->data);
			}

			if (g_strcmp0 (node->data, "hostname") == 0) {
				config->oci.hostname = g_strdup (node->children->data);
			}
		}

		/* looking for right spec handler */
		for (struct spec_handler** i=spec_handlers; (*i); ++i) {
			if (g_strcmp0((*i)->name, node->data) == 0) {
				/* run spec handler */
				if (! (*i)->handle_section(node, config)) {
					g_critical("failed spec handler: %s", (*i)->name);
					return false;
				}
				break;
			}
		}
	}

	return true;
}
Ejemplo n.º 24
0
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
}
Ejemplo n.º 25
0
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);
	}
}
Ejemplo n.º 26
0
static void    
ltable_notify(LTable* lt, const gchar* key,
              MateConfListenersCallback callback, gpointer user_data)
{
  gchar** dirs;
  guint i;
  const gchar* noroot_key;
  GNode* cur;
  GList *to_notify;
  
  noroot_key = key + 1;

  g_return_if_fail(*key == '/');
  g_return_if_fail(mateconf_valid_key(key, NULL));

  if (lt->tree == NULL)
    return; /* no one to notify */

  /* we build a list "to_notify" to be safe against tree
   * modifications during the notification.
   */
  
  /* Notify "/" listeners */
  to_notify = g_list_copy (((LTableEntry*)lt->tree->data)->listeners);  

  dirs = g_strsplit (noroot_key, "/", -1);

  cur = lt->tree;
  i = 0;
  while (dirs[i] && cur)
    {
      GNode* child = cur->children;

      while (child != NULL)
        {
          LTableEntry* lte = child->data;

          if (strcmp(lte->name, dirs[i]) == 0)
            {
              GList *copy = g_list_copy (lte->listeners);
              to_notify = g_list_concat (to_notify, copy);

              break;
            }

          child = g_node_next_sibling(child);
        }

      if (child != NULL) /* we found a child, scan below it */
        cur = child;
      else               /* end of the line */
        cur = NULL;

      ++i;
    }
  
  g_strfreev(dirs);

  g_list_foreach (to_notify, (GFunc) listener_ref, NULL);
  
  notify_listener_list ((MateConfListeners*)lt,
                        to_notify, key,
                        callback, user_data);

  g_list_foreach (to_notify, (GFunc) listener_unref, NULL);

  g_list_free (to_notify);
}
Ejemplo n.º 27
0
GNode*
ada_gnode_next_sibling (GNode * node)
{
  return g_node_next_sibling (node);
}
Ejemplo n.º 28
0
plist_t plist_get_next_sibling(plist_t node)
{
	return (plist_t) g_node_next_sibling((GNode *) node);
}