Ejemplo n.º 1
0
/**
 * This allocates a property node for use in the property AVL tree.  The
 * note has the given name (memory is copied over) and is set dirty, but
 * otherwise is a blank slate ready to be added to the AVL.
 *
 * Chances are, you do not want to use this method.  It is exposed because
 * it is used in boolexp.c and props.c
 *
 * @internal
 * @param name String property name (memory will be copied)
 * @return allocated PropPtr AVL node.
 */
PropPtr
alloc_propnode(const char *name)
{
    PropPtr new_node;
    size_t nlen = strlen(name);

    new_node = malloc(sizeof(struct plist) + nlen);

    if (!new_node) {
        fprintf(stderr, "alloc_propnode(): Out of Memory!\n");
        abort();
    }

    new_node->left = NULL;
    new_node->right = NULL;
    new_node->height = 1;

    strcpyn(PropName(new_node), nlen + 1, name);
    SetPFlagsRaw(new_node, PROP_DIRTYP);
    SetPDataVal(new_node, 0);
    SetPDir(new_node, NULL);
    return new_node;
}
Ejemplo n.º 2
0
/* path is the name of the property to delete */
PropPtr
propdir_delete_elem(PropPtr root, char *path)
{
	PropPtr p;
	char *n;

	if (!root)
		return (NULL);
	while (*path && *path == PROPDIR_DELIMITER)
		path++;
	if (!*path)
		return (root);
	n = index(path, PROPDIR_DELIMITER);
	while (n && *n == PROPDIR_DELIMITER)
		*(n++) = '\0';
	if (n && *n) {
		/* just another propdir in the path */
		p = locate_prop(root, path);
		if (p && PropDir(p)) {
			/* yup, found the propdir */
			SetPDir(p, propdir_delete_elem(PropDir(p), n));
			if (!PropDir(p) && PropType(p) == PROP_DIRTYP) {
				root = delete_prop(&root, PropName(p));
			}
		}
		/* return the updated root pntr */
		return (root);
	} else {
		/* aha, we are finally to the property itself. */
		p = locate_prop(root, path);
		if (p && PropDir(p)) {
			delete_proplist(PropDir(p));
		}
		(void) delete_prop(&root, path);
		return (root);
	}
}