Beispiel #1
0
/** Delete a branch of the tree.
 * Deletes a subtree pointed to by path.  If more than one matching entry
 * exists, the first one will be deleted. If del_empty==1, and by removing
 * the parent tree becomes empty, the parents will be removed recursively.
 * If del_empty==0, an empty subtree may be left behind.
 * In any case, memory of the subtree and deleted parents will be freed.
 * @param [in] cn_root pointer to the root of the tree
 * @param [in] path the path of the tree to be deleted
 * @param [in] del_empty set to 1 if empty parents shall be removed.
 */
int cnf_del_branch(struct cnfnode *cn_root, const char *path, int del_empty)
{
	struct cnfresult *cr;

	cr = cnf_find_entry_f(cn_root, path, FIND_ENTRY_FLAG_NOPATH|FIND_ENTRY_FLAG_FIRST);
	if(cr){
		struct cnfnode *cn_top = cr->cnfnode;

		unlink_node(cn_top);

		if(del_empty){
			/* must be done after unlink_(), so it does not find this one in the search
			   below, and before destroy_(), because we still need to access the structure. */
			struct cnfnode *cn;

			for(cn = cn_top->parent; cn->parent && cn != cn_root; cn = cn->parent){
				if(cn->first_child == NULL){
					unlink_node(cn);
					destroy_cnftree(cn);
				}
			}
		}
		destroy_cnftree(cn_top);

		destroy_cnfresult_list(cr);
		return 0;
	}

	errno = ENOENT;
	return -ENOENT;
}
Beispiel #2
0
/* Update a history list.  h should be the current position in the
 * list. */
void update_history(linestruct **h, const char *s)
{
    linestruct **hage = NULL, **hbot = NULL, *p;

    assert(h != NULL && s != NULL);

    if (*h == search_history) {
	hage = &searchage;
	hbot = &searchbot;
    } else if (*h == replace_history) {
	hage = &replaceage;
	hbot = &replacebot;
    }

    assert(hage != NULL && hbot != NULL);

    /* If this string is already in the history, delete it. */
    p = find_history(*hage, *hbot, s, strlen(s));

    if (p != NULL) {
	linestruct *foo, *bar;

	/* If the string is at the beginning, move the beginning down to
	 * the next string. */
	if (p == *hage)
	    *hage = (*hage)->next;

	/* Delete the string. */
	foo = p;
	bar = p->next;
	unlink_node(foo);
	delete_node(foo);
	renumber(bar);
    }

    /* If the history is full, delete the beginning entry to make room
     * for the new entry at the end.  We assume that MAX_SEARCH_HISTORY
     * is greater than zero. */
    if ((*hbot)->lineno == MAX_SEARCH_HISTORY + 1) {
	linestruct *foo = *hage;

	*hage = (*hage)->next;
	unlink_node(foo);
	delete_node(foo);
	renumber(*hage);
    }

    /* Add the new entry to the end. */
    (*hbot)->data = mallocstrcpy((*hbot)->data, s);
    splice_node(*hbot, make_new_node(*hbot), (*hbot)->next);
    *hbot = (*hbot)->next;
    (*hbot)->data = mallocstrcpy(NULL, "");

    /* Indicate that the history's been changed. */
    history_changed = TRUE;

    /* Set the current position in the list to the bottom. */
    *h = *hbot;
}
Beispiel #3
0
/* Update a history list (the one in which item is the current position)
 * with a fresh string text.  That is: add text, or move it to the end. */
void update_history(linestruct **item, const char *text)
{
	linestruct **htop = NULL, **hbot = NULL, *thesame;

	if (*item == search_history) {
		htop = &searchtop;
		hbot = &searchbot;
	} else if (*item == replace_history) {
		htop = &replacetop;
		hbot = &replacebot;
	} else if (*item == execute_history) {
		htop = &executetop;
		hbot = &executebot;
	}

	/* See if the string is already in the history. */
	thesame = find_history(*hbot, *htop, text, HIGHEST_POSITIVE);

	/* If an identical string was found, delete that item. */
	if (thesame != NULL) {
		linestruct *after = thesame->next;

		/* If the string is at the head of the list, move the head. */
		if (thesame == *htop)
			*htop = after;

		unlink_node(thesame);
		renumber_from(after);
	}

	/* If the history is full, delete the oldest item (the one at the
	 * head of the list), to make room for a new item at the end. */
	if ((*hbot)->lineno == MAX_SEARCH_HISTORY + 1) {
		linestruct *oldest = *htop;

		*htop = (*htop)->next;
		unlink_node(oldest);
		renumber_from(*htop);
	}

	/* Store the fresh string in the last item, then create a new item. */
	(*hbot)->data = mallocstrcpy((*hbot)->data, text);
	splice_node(*hbot, make_new_node(*hbot));
	*hbot = (*hbot)->next;
	(*hbot)->data = mallocstrcpy(NULL, "");

	/* Indicate that the history needs to be saved on exit. */
	history_changed = TRUE;

	/* Set the current position in the list to the bottom. */
	*item = *hbot;
}
Beispiel #4
0
void transfer_node(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd, node_t *n)
{
    if (n == NULL || ds == NULL || dd == NULL || ms == NULL || md == NULL || (ms == md && dd == ds))
        return;

    PRINTF("transfer node %X\n", n->client->window);

    unlink_node(ds, n);
    insert_node(md, dd, n);
    ewmh_set_wm_desktop(n, dd);

    if (ds == ms->desk && dd != md->desk) {
        window_hide(n->client->window);
    }

    fit_monitor(md, n->client);

    if (n->client->fullscreen)
        window_move_resize(n->client->window, md->rectangle.x, md->rectangle.y, md->rectangle.width, md->rectangle.height);

    if (ds != ms->desk && dd == md->desk) {
        window_show(n->client->window);
        focus_node(md, dd, n, true);
    } else {
        focus_node(md, dd, n, false);
    }

    if (ds == ms->desk || dd == md->desk)
        update_current();
}
result_t examine_del_end(list_t *list, data_t *p_object)
{
	if(is_empty(list) == TRUE)
	{
		return (ERROR);
	}

	node_t *head = get_last_node(list);
	*p_object = head -> data;
	unlink_node(head);

	return (SUCCESS);
}
result_t examine_del_beg(list_t *list, data_t *p_object)
{
	if(is_empty(list) == TRUE)
	{
		return (ERROR);	
	}

	node_t *head = list -> next;
	*p_object = head -> data;
	unlink_node(head);

	return (SUCCESS);
}
Beispiel #7
0
/** Strip comments and empty lines from the tree.
 * In particular, all nodes with names starting with a dot are removed from the tree.
 * This will include any <tt>.comment</tt>, <tt>.empty</tt> or <tt>.unparsed</tt> nodes, for example.
 * @param [in] cn_root A pointer to the root of the tree which is to be stripped.
 */
void strip_cnftree(struct cnfnode *cn_root)
{
	struct cnfnode *cn, *cn_next;

	for(cn = cn_root->first_child; cn; cn = cn_next){
		cn_next = cn->next;

		strip_cnftree(cn);

		if(cn->name[0] == '.'){
			unlink_node(cn);
			destroy_cnftree(cn);
		}
	}
}
Beispiel #8
0
void
free_node (Node *node, gboolean unlink_node_first)
{
  if (unlink_node_first)
    {
      unlink_node (node);
    }
  else
    {
      g_list_free (node->neighbors);
      g_list_free (node->linked_nodes);
      node->neighbors = NULL;
      node->linked_nodes = NULL;
    }
  g_slice_free (Node, node);
}
result_t delete_begin(list_t *list)
{

	node_t *target;

	if(is_empty(list) == TRUE)
	{
		return (ERROR);
	}	

	target = list -> next;

	unlink_node(target);

	return (SUCCESS);
}
Beispiel #10
0
void remove_node(desktop_t *d, node_t *n)
{
    if (d == NULL || n == NULL)
        return;

    PRINTF("remove node %X\n", n->client->window);

    unlink_node(d, n);
    free(n->client);
    free(n);

    num_clients--;
    ewmh_update_client_list();

    if (mon->desk == d)
        update_current();
}
result_t delete_end(list_t *list)
{
	node_t *target;

	if(is_empty(list) == TRUE)
	{
		return (ERROR);
	}

	target = get_last_node(list); 
	
	if(target != NULL)
	{
		unlink_node(target);
		return (SUCCESS);
	}
	else
	{
		return (ERROR);
	}
}
result_t delete_data(list_t *list, data_t data)
{
	node_t *run, *target;
	
	if(is_empty(list) == TRUE)
	{
		return (ERROR);
	}

	run = list -> next;
	target = search_node(list, data);

	if(target != NULL) 
	{
		unlink_node(target);
		return (SUCCESS);
	}
	else
	{
		return (ERROR);
	}
}