#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "cbf.h"#include "cbf_alloc.h"#include "cbf_tree.h"#include "cbf_context.h"#include "cbf_binary.h"
Go to the source code of this file.
Functions | |
| int | cbf_make_node (cbf_node **node, CBF_NODETYPE type, cbf_context *context, const char *name) |
| int | cbf_make_new_node (cbf_node **node, CBF_NODETYPE type, cbf_context *context, const char *name) |
| int | cbf_free_node (cbf_node *node) |
| int | cbf_set_children (cbf_node *node, unsigned int children) |
| cbf_node * | cbf_get_link (const cbf_node *node) |
| int | cbf_find_child (cbf_node **child, const cbf_node *node, const char *name) |
| int | cbf_find_last_child (cbf_node **child, const cbf_node *node, const char *name) |
| int | cbf_find_parent (cbf_node **parent, const cbf_node *node, CBF_NODETYPE type) |
| int | cbf_count_children (unsigned int *children, const cbf_node *node) |
| int | cbf_child_index (unsigned int *index, const cbf_node *node) |
| int | cbf_get_child (cbf_node **child, const cbf_node *node, unsigned int index) |
| int | cbf_get_name (const char **name, cbf_node *node) |
| int | cbf_name_node (cbf_node *node, const char *name) |
| int | cbf_name_new_node (cbf_node *node, const char *name) |
| int | cbf_add_child (cbf_node *node, cbf_node *child) |
| int | cbf_add_new_child (cbf_node *node, cbf_node *child) |
| int | cbf_make_child (cbf_node **child, cbf_node *node, CBF_NODETYPE type, const char *name) |
| int | cbf_make_new_child (cbf_node **child, cbf_node *node, CBF_NODETYPE type, const char *name) |
| int | cbf_set_link (cbf_node *link, cbf_node *node) |
| int | cbf_add_link (cbf_node *link, cbf_node *child) |
| int | cbf_shift_link (cbf_node *link) |
| int | cbf_set_columnrow (cbf_node *column, unsigned int row, const char *value, int free) |
| int | cbf_get_columnrow (const char **value, const cbf_node *column, unsigned int row) |
| int | cbf_insert_columnrow (cbf_node *column, unsigned int row, const char *value) |
| int | cbf_delete_columnrow (cbf_node *column, unsigned int row) |
| int | cbf_add_columnrow (cbf_node *column, const char *value) |
Definition at line 859 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_failnez, cbf_find_child(), cbf_get_link(), CBF_IDENTICAL, cbf_set_children(), cbf_compress_nodestruct::child, cbf_node_struct::child, cbf_node_struct::children, cbf_node_struct::name, and cbf_node_struct::parent.
Referenced by cbf_make_child().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the first argument */
if (!node)
return CBF_ARGUMENT;
/* Follow any links */
child = cbf_get_link (child);
/* Check the second argument */
if (!child)
return CBF_ARGUMENT;
/* Is there already a child with this name? */
if (cbf_find_child (NULL, node, child->name) == 0)
return CBF_IDENTICAL;
/* Add the child */
cbf_failnez (cbf_set_children (node, node->children + 1))
child->parent = node;
node->child [node->children - 1] = child;
/* Success */
return 0;
}
| int cbf_add_columnrow | ( | cbf_node * | column, |
| const char * | value | ||
| ) |
Definition at line 1344 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_get_link(), cbf_set_columnrow(), and cbf_node_struct::children.
Referenced by cbf_new_row(), and yyparse().
{
/* Follow any links */
column = cbf_get_link (column);
/* Check the arguments */
if (!column)
return CBF_ARGUMENT;
/* Add the value */
return cbf_set_columnrow (column, column->children, value, 1);
}
Definition at line 1093 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_failnez, CBF_LINK, cbf_set_children(), cbf_compress_nodestruct::child, cbf_node_struct::child, cbf_node_struct::children, and cbf_node_struct::type.
Referenced by yyparse().
{
/* Check the arguments */
if (!link)
return CBF_ARGUMENT;
/* Check the type */
if (link->type != CBF_LINK)
return CBF_ARGUMENT;
/* Add the child */
cbf_failnez (cbf_set_children (link, link->children + 1))
link->child [link->children - 1] = child;
/* Success */
return 0;
}
Definition at line 909 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_failnez, cbf_get_link(), cbf_set_children(), cbf_compress_nodestruct::child, cbf_node_struct::child, cbf_node_struct::children, and cbf_node_struct::parent.
Referenced by cbf_make_new_child().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the first argument */
if (!node)
return CBF_ARGUMENT;
/* Follow any links */
child = cbf_get_link (child);
/* Check the second argument */
if (!child)
return CBF_ARGUMENT;
/* Add the child */
cbf_failnez (cbf_set_children (node, node->children + 1))
child->parent = node;
node->child [node->children - 1] = child;
/* Success */
return 0;
}
| int cbf_child_index | ( | unsigned int * | index, |
| const cbf_node * | node | ||
| ) |
Definition at line 668 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::child, cbf_compress_nodestruct::child, cbf_node_struct::children, and cbf_node_struct::parent.
Referenced by cbf_next_category(), cbf_next_column(), and cbf_next_datablock().
{
cbf_node *parent;
unsigned int child;
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Get the parent */
parent = node->parent;
if (!parent)
return CBF_NOTFOUND;
/* Find the child */
for (child = 0; child < parent->children; child++)
if (parent->child [child] == node)
{
if (index)
*index = child;
return 0;
}
/* Fail */
return CBF_NOTFOUND;
}
| int cbf_count_children | ( | unsigned int * | children, |
| const cbf_node * | node | ||
| ) |
Definition at line 644 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_get_link(), and cbf_node_struct::children.
Referenced by cbf_count_categories(), cbf_count_columns(), cbf_count_datablocks(), cbf_count_rows(), cbf_find_nextrow(), cbf_next_row(), cbf_read_file(), cbf_reset_datablocks(), and cbf_select_row().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!children || !node)
return CBF_ARGUMENT;
/* Success */
*children = node->children;
return 0;
}
| int cbf_delete_columnrow | ( | cbf_node * | column, |
| unsigned int | row | ||
| ) |
Definition at line 1303 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_failnez, cbf_get_link(), CBF_NOTFOUND, cbf_set_children(), cbf_set_columnrow(), cbf_node_struct::child, and cbf_node_struct::children.
Referenced by cbf_delete_row(), and cbf_insert_row().
{
/* Follow any links */
column = cbf_get_link (column);
/* Check the arguments */
if (!column)
return CBF_ARGUMENT;
if (row >= column->children)
return CBF_NOTFOUND;
/* Free the value */
cbf_failnez (cbf_set_columnrow (column, row, NULL, 1))
/* Move any values further down the column */
if (row < column->children - 1)
memmove (column->child + row, column->child + row + 1,
sizeof (cbf_node *) * (column->children - row - 1));
column->child [column->children - 1] = NULL;
/* Decrease the column size */
return cbf_set_children (column, column->children - 1);
}
Definition at line 467 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::child, cbf_node_struct::children, cbf_compress_nodestruct::count, cbf_node_struct::name, and cbf_node_struct::type.
Referenced by cbf_add_child(), cbf_find_category(), cbf_find_column(), cbf_find_datablock(), and cbf_name_node().
{
unsigned int count;
const char *namec, *nodenamec;
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Is it a normal node? */
if (node->type == CBF_COLUMN)
return CBF_ARGUMENT;
/* Search the children */
for (count = 0; count < node->children; count++)
if (name)
{
if (node->child [count]->name)
{
for (namec = name, nodenamec = node->child [count]->name;
*namec && toupper (*nodenamec) == toupper (*namec);
namec++, nodenamec++);
if (!*namec && !*nodenamec)
{
if (child)
*child = node->child [count];
return 0;
}
}
}
else
if (name == node->child [count]->name)
{
if (child)
*child = node->child [count];
return 0;
}
/* Fail */
return CBF_NOTFOUND;
}
Definition at line 535 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::child, cbf_node_struct::children, cbf_compress_nodestruct::count, cbf_node_struct::name, and cbf_node_struct::type.
Referenced by cbf_make_child().
{
int count;
const char *namec, *nodenamec;
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Is it a normal node? */
if (node->type == CBF_COLUMN)
return CBF_ARGUMENT;
/* Search the children */
for (count = ((int) node->children) - 1; count >= 0; count--)
if (name)
{
if (node->child [count]->name)
{
for (namec = name, nodenamec = node->child [count]->name;
*namec && toupper (*nodenamec) == toupper (*namec);
namec++, nodenamec++);
if (!*namec && !*nodenamec)
{
if (child)
*child = node->child [count];
return 0;
}
}
}
else
if (name == node->child [count]->name)
{
if (child)
*child = node->child [count];
return 0;
}
/* Fail */
return CBF_NOTFOUND;
}
| int cbf_find_parent | ( | cbf_node ** | parent, |
| const cbf_node * | node, | ||
| CBF_NODETYPE | type | ||
| ) |
Definition at line 604 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::parent, and cbf_node_struct::type.
Referenced by cbf_category_name(), cbf_column_name(), cbf_count_categories(), cbf_count_columns(), cbf_count_datablocks(), cbf_count_rows(), cbf_datablock_name(), cbf_delete_row(), cbf_find_category(), cbf_find_column(), cbf_find_datablock(), cbf_find_nextrow(), cbf_force_new_category(), cbf_force_new_datablock(), cbf_insert_row(), cbf_new_category(), cbf_new_column(), cbf_new_datablock(), cbf_new_row(), cbf_next_category(), cbf_next_column(), cbf_next_datablock(), cbf_next_row(), cbf_read_file(), cbf_remove_category(), cbf_remove_column(), cbf_remove_datablock(), cbf_reset_category(), cbf_reset_datablock(), cbf_reset_datablocks(), cbf_rewind_category(), cbf_rewind_column(), cbf_rewind_datablock(), cbf_select_category(), cbf_select_column(), cbf_select_datablock(), cbf_select_row(), cbf_set_datablockname(), cbf_write_file(), cbf_write_itemname(), and yyparse().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Find the parent */
while (node)
{
if (node->type == type)
{
if (parent)
*parent = (cbf_node *) node;
return 0;
}
node = node->parent;
}
/* Fail */
return CBF_NOTFOUND;
}
| int cbf_free_node | ( | cbf_node * | node | ) |
Definition at line 294 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_delete_contextconnection(), cbf_failnez, cbf_free(), cbf_free_string(), cbf_set_children(), cbf_node_struct::child, cbf_node_struct::child_size, cbf_node_struct::children, cbf_node_struct::context, cbf_compress_nodestruct::count, cbf_node_struct::name, and cbf_node_struct::parent.
Referenced by cbf_free_handle(), cbf_make_child(), cbf_make_new_child(), cbf_make_new_node(), cbf_make_node(), cbf_new_column(), cbf_read_file(), cbf_remove_category(), cbf_remove_column(), cbf_remove_datablock(), and cbf_set_children().
{
unsigned int count;
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Disconnect the node from its parent? */
if (node->parent)
for (count = 0; count < node->parent->children; count++)
if (node->parent->child [count] == node)
{
node->parent->children--;
if (node->parent->children == 0)
cbf_failnez (cbf_free ((void **) &node->parent->child,
&node->parent->child_size))
else
if (node->parent->children > count)
memmove (node->parent->child + count,
node->parent->child + count + 1,
(node->parent->children - count) * sizeof (cbf_node *));
break;
}
/* Free the children */
cbf_failnez (cbf_set_children (node, 0))
/* Free the name */
cbf_free_string (NULL, node->name);
/* Free the context connection */
cbf_failnez (cbf_delete_contextconnection (&node->context))
/* Free the node */
return cbf_free ((void **) &node, NULL);
}
Definition at line 718 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::child, and cbf_node_struct::type.
Referenced by cbf_count_rows(), cbf_delete_row(), cbf_insert_row(), cbf_new_row(), cbf_next_category(), cbf_next_column(), cbf_next_datablock(), cbf_read_file(), cbf_reset_datablocks(), cbf_rewind_category(), cbf_rewind_column(), cbf_rewind_datablock(), cbf_select_category(), cbf_select_column(), and cbf_select_datablock().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Is it a normal node? */
if (node->type == CBF_COLUMN)
return CBF_ARGUMENT;
/* Does the child exists? */
if (index < node->children)
{
if (child)
*child = node->child [index];
return 0;
}
/* Fail */
return CBF_NOTFOUND;
}
| int cbf_get_columnrow | ( | const char ** | value, |
| const cbf_node * | column, | ||
| unsigned int | row | ||
| ) |
Definition at line 1217 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_get_link(), CBF_NOTFOUND, cbf_node_struct::child, cbf_node_struct::children, and cbf_node_struct::type.
Referenced by cbf_find_nextrow(), cbf_free_value(), cbf_get_bintext(), cbf_get_value(), cbf_is_binary(), cbf_is_mimebinary(), and cbf_write_value().
{
/* Follow any links */
column = cbf_get_link (column);
/* Check the arguments */
if (!column)
return CBF_ARGUMENT;
/* Check the node type */
if (column->type != CBF_COLUMN)
return CBF_ARGUMENT;
/* Is the value in the column? */
if (row + 1 > column->children)
return CBF_NOTFOUND;
/* Success */
if (value)
*value = (const char *) column->child [row];
return 0;
}
Definition at line 446 of file cbf_tree.c.
References CBF_LINK, cbf_node_struct::link, and cbf_node_struct::type.
Referenced by cbf_add_child(), cbf_add_columnrow(), cbf_add_new_child(), cbf_child_index(), cbf_count_children(), cbf_delete_columnrow(), cbf_find_child(), cbf_find_last_child(), cbf_find_parent(), cbf_get_child(), cbf_get_columnrow(), cbf_get_name(), cbf_insert_columnrow(), cbf_make_child(), cbf_make_new_child(), cbf_name_new_node(), cbf_name_node(), cbf_set_columnrow(), and cbf_write_node().
| int cbf_get_name | ( | const char ** | name, |
| cbf_node * | node | ||
| ) |
Definition at line 759 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_get_link(), and cbf_node_struct::name.
Referenced by cbf_category_name(), cbf_column_name(), cbf_datablock_name(), and cbf_read_file().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Set the name */
if (name)
*name = node->name;
/* Success */
return 0;
}
| int cbf_insert_columnrow | ( | cbf_node * | column, |
| unsigned int | row, | ||
| const char * | value | ||
| ) |
Definition at line 1258 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_failnez, cbf_get_link(), CBF_NOTFOUND, cbf_set_children(), cbf_node_struct::child, and cbf_node_struct::children.
Referenced by cbf_insert_row().
{
/* Follow any links */
column = cbf_get_link (column);
/* Check the arguments */
if (!column)
return CBF_ARGUMENT;
if (row > column->children)
return CBF_NOTFOUND;
/* Increase the column size */
cbf_failnez (cbf_set_children (column, column->children + 1))
/* Move any values further down the column */
if (row < column->children - 1)
memmove (column->child + row + 1, column->child + row,
sizeof (cbf_node *) * (column->children - row - 1));
/* Set the value */
column->child [row] = (cbf_node *) value;
/* Success */
return 0;
}
| int cbf_make_child | ( | cbf_node ** | child, |
| cbf_node * | node, | ||
| CBF_NODETYPE | type, | ||
| const char * | name | ||
| ) |
Definition at line 952 of file cbf_tree.c.
References cbf_add_child(), CBF_ARGUMENT, cbf_failnez, cbf_find_last_child(), cbf_free_node(), cbf_free_string(), cbf_get_link(), CBF_LINK, cbf_make_node(), CBF_NOTFOUND, cbf_node_struct::context, and cbf_node_struct::name.
Referenced by cbf_new_category(), cbf_new_column(), cbf_new_datablock(), and yyparse().
{
cbf_node *newchild;
int errorcode;
/* Check the type */
if (type == CBF_LINK)
return CBF_ARGUMENT;
/* Follow any links */
node = cbf_get_link (node);
/* Does the child already exist? */
errorcode = cbf_find_last_child (child, node, name);
if (errorcode == 0)
{
cbf_free_string (NULL, name);
return 0;
}
if (errorcode != CBF_NOTFOUND)
return errorcode;
/* Make a new node */
cbf_failnez (cbf_make_node (&newchild, type, node->context, name))
errorcode = cbf_add_child (node, newchild);
if (errorcode)
{
newchild->name = NULL;
cbf_free_node (newchild);
return errorcode;
}
/* Success */
if (child)
*child = newchild;
return 0;
}
| int cbf_make_new_child | ( | cbf_node ** | child, |
| cbf_node * | node, | ||
| CBF_NODETYPE | type, | ||
| const char * | name | ||
| ) |
Definition at line 1016 of file cbf_tree.c.
References cbf_add_new_child(), CBF_ARGUMENT, cbf_failnez, cbf_free_node(), cbf_get_link(), CBF_LINK, cbf_make_new_node(), cbf_node_struct::context, and cbf_node_struct::name.
Referenced by cbf_force_new_category(), cbf_force_new_datablock(), and yyparse().
{
cbf_node *newchild;
int errorcode;
/* Check the type */
if (type == CBF_LINK)
return CBF_ARGUMENT;
/* Follow any links */
node = cbf_get_link (node);
/* Make a new node */
cbf_failnez (cbf_make_new_node (&newchild, type, node->context, name))
errorcode = cbf_add_new_child (node, newchild);
if (errorcode)
{
newchild->name = NULL;
cbf_free_node (newchild);
return errorcode;
}
/* Success */
if (child)
*child = newchild;
return 0;
}
| int cbf_make_new_node | ( | cbf_node ** | node, |
| CBF_NODETYPE | type, | ||
| cbf_context * | context, | ||
| const char * | name | ||
| ) |
Definition at line 216 of file cbf_tree.c.
References cbf_add_contextconnection(), cbf_alloc(), CBF_ARGUMENT, cbf_failnez, cbf_free(), cbf_free_context(), cbf_free_node(), CBF_LINK, cbf_name_new_node(), and cbf_onfailnez.
Referenced by cbf_make_new_child().
{
int errorcode;
if (!node)
return CBF_ARGUMENT;
/* Create the new node */
cbf_failnez (cbf_alloc ((void **) node, NULL, sizeof (cbf_node), 1))
/* Initialise the node */
(*node)->type = type;
(*node)->name = NULL;
(*node)->link = NULL;
(*node)->parent = NULL;
(*node)->children = 0;
(*node)->child_size = 0;
(*node)->child = NULL;
/* Add the context? */
if (type == CBF_LINK)
(*node)->context = NULL;
else
{
/* Does the context exist? */
if (context)
(*node)->context = context;
else
(*node)->context = NULL;
/* Add a context connection */
cbf_onfailnez (cbf_add_contextconnection (&(*node)->context),
cbf_free ((void **) node, NULL))
/* Name the node */
errorcode = cbf_name_new_node (*node, name);
if (errorcode)
{
errorcode |= cbf_free_context (&(*node)->context);
return errorcode | cbf_free_node (*node);
}
}
/* Success */
return 0;
}
| int cbf_make_node | ( | cbf_node ** | node, |
| CBF_NODETYPE | type, | ||
| cbf_context * | context, | ||
| const char * | name | ||
| ) |
Definition at line 138 of file cbf_tree.c.
References cbf_add_contextconnection(), cbf_alloc(), CBF_ARGUMENT, cbf_failnez, cbf_free(), cbf_free_context(), cbf_free_node(), CBF_LINK, cbf_name_node(), and cbf_onfailnez.
Referenced by cbf_make_child(), cbf_make_handle(), and yyparse().
{
int errorcode;
if (!node)
return CBF_ARGUMENT;
/* Create the new node */
cbf_failnez (cbf_alloc ((void **) node, NULL, sizeof (cbf_node), 1))
/* Initialise the node */
(*node)->type = type;
(*node)->name = NULL;
(*node)->link = NULL;
(*node)->parent = NULL;
(*node)->children = 0;
(*node)->child_size = 0;
(*node)->child = NULL;
/* Add the context? */
if (type == CBF_LINK)
(*node)->context = NULL;
else
{
/* Does the context exist? */
if (context)
(*node)->context = context;
else
(*node)->context = NULL;
/* Add a context connection */
cbf_onfailnez (cbf_add_contextconnection (&(*node)->context),
cbf_free ((void **) node, NULL))
/* Name the node */
errorcode = cbf_name_node (*node, name);
if (errorcode)
{
errorcode |= cbf_free_context (&(*node)->context);
return errorcode | cbf_free_node (*node);
}
}
/* Success */
return 0;
}
| int cbf_name_new_node | ( | cbf_node * | node, |
| const char * | name | ||
| ) |
Definition at line 830 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_free_string(), cbf_get_link(), and cbf_node_struct::name.
Referenced by cbf_make_new_node().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Replace the old name */
cbf_free_string (NULL, node->name);
node->name = (char *) name;
/* Success */
return 0;
}
| int cbf_name_node | ( | cbf_node * | node, |
| const char * | name | ||
| ) |
Definition at line 792 of file cbf_tree.c.
References CBF_ARGUMENT, cbf_find_child(), cbf_free_string(), cbf_get_link(), CBF_IDENTICAL, cbf_node_struct::name, and cbf_node_struct::parent.
Referenced by cbf_make_node(), and cbf_set_datablockname().
{
/* Follow any links */
node = cbf_get_link (node);
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Is there a sibling with this name? */
if (node->parent)
if (cbf_find_child (NULL, node->parent, name) == 0)
return CBF_IDENTICAL;
/* Replace the old name */
cbf_free_string (NULL, node->name);
node->name = name;
/* Success */
return 0;
}
| int cbf_set_children | ( | cbf_node * | node, |
| unsigned int | children | ||
| ) |
Definition at line 356 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_failnez, cbf_free(), cbf_free_node(), CBF_LINK, cbf_realloc(), cbf_set_columnrow(), cbf_node_struct::child, cbf_node_struct::child_size, cbf_node_struct::children, cbf_compress_nodestruct::count, cbf_node_struct::parent, and cbf_node_struct::type.
Referenced by cbf_add_child(), cbf_add_link(), cbf_add_new_child(), cbf_delete_columnrow(), cbf_free_node(), cbf_insert_columnrow(), cbf_new_column(), cbf_new_row(), cbf_read_file(), cbf_reset_category(), cbf_reset_datablock(), cbf_reset_datablocks(), and cbf_set_columnrow().
{
unsigned int count, new_size, kblock;
int errorcode;
/* Check the arguments */
if (!node)
return CBF_ARGUMENT;
/* Is the current size correct? */
if (children == node->children)
return 0;
/* Compute a target new size */
kblock = 16;
if (children > 128*2) kblock = 128;
if (children > 512*2) kblock = 512;
new_size = (((int)((children -1)/kblock)))*kblock+kblock;
if (new_size < children) new_size = children;
/* Decrease the number of children? */
if (children < node->children)
{
errorcode = 0;
for (count = children; count < node->children; count++)
/* Free the child */
if (node->type == CBF_COLUMN)
errorcode |= cbf_set_columnrow (node, count, NULL, 1);
else
if (node->type != CBF_LINK)
if (node->child [count])
{
node->child [count]->parent = NULL;
errorcode |= cbf_free_node (node->child [count]);
node->child [count] = NULL;
}
if (children == 0)
errorcode = cbf_free ((void **) &node->child, &node->child_size);
node->children = children;
if (new_size < node->child_size )
cbf_failnez (cbf_realloc ((void * *) &node->child, &node->child_size,
sizeof (cbf_node *), new_size))
return errorcode;
}
/* Increase the number of children */
if (new_size > node->child_size)
cbf_failnez (cbf_realloc ((void **) &node->child, &node->child_size,
sizeof (cbf_node *), new_size))
node->children = children;
/* Success */
return 0;
}
| int cbf_set_columnrow | ( | cbf_node * | column, |
| unsigned int | row, | ||
| const char * | value, | ||
| int | free | ||
| ) |
Definition at line 1168 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_COLUMN, cbf_failnez, cbf_free_value(), cbf_get_link(), cbf_set_children(), cbf_node_struct::child, cbf_node_struct::children, cbf_node_struct::context, and cbf_node_struct::type.
Referenced by cbf_add_columnrow(), cbf_delete_columnrow(), cbf_free_value(), cbf_set_binary(), cbf_set_bintext(), cbf_set_children(), cbf_set_value(), and yyparse().
{
/* Follow any links */
column = cbf_get_link (column);
/* Check the arguments */
if (!column)
return CBF_ARGUMENT;
/* Check the node type */
if (column->type != CBF_COLUMN)
return CBF_ARGUMENT;
/* Increase the column size? */
if (row + 1 > column->children)
cbf_failnez (cbf_set_children (column, row + 1))
/* Remove the old value */
if (free)
cbf_failnez (cbf_free_value (column->context, column, row))
/* Set the new value */
column->child [row] = (cbf_node *) value;
/* Success */
return 0;
}
Definition at line 1064 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_LINK, cbf_node_struct::link, and cbf_node_struct::type.
Referenced by yyparse().
{
/* Check the arguments */
if (!link)
return CBF_ARGUMENT;
/* Check the type */
if (link->type != CBF_LINK)
return CBF_ARGUMENT;
/* Change the link */
link->link = node;
/* Success */
return 0;
}
| int cbf_shift_link | ( | cbf_node * | link | ) |
Definition at line 1124 of file cbf_tree.c.
References CBF_ARGUMENT, CBF_LINK, cbf_node_struct::child, cbf_node_struct::children, cbf_node_struct::link, and cbf_node_struct::type.
Referenced by yyparse().
{
/* Check the arguments */
if (!link)
return CBF_ARGUMENT;
/* Check the type */
if (link->type != CBF_LINK)
return CBF_ARGUMENT;
/* Do the children exist? */
if (link->children == 0)
return CBF_ARGUMENT;
/* Change the link */
link->link = link->child [0];
/* Shift the children */
memmove (link->child, link->child + 1,
(link->children - 1) * sizeof (cbf_node *));
link->child [link->children - 1] = link->link;
/* Success */
return 0;
}
1.7.3