llconf  0.0.2
Data Structures | Functions
nodes.h File Reference

Data Structures

struct  cnfnode
 A node in a parsed configuration tree. More...
 

Functions

struct cnfnodecreate_cnfnode (const char *name)
 creates an empty node. More...
 
struct cnfnodeclone_cnfnode (const struct cnfnode *cn)
 copies a node. More...
 
struct cnfnodeclone_cnftree (const struct cnfnode *cn_root)
 copy a whole tree. More...
 
const char * cnfnode_getval (const struct cnfnode *cn)
 gets the value of a node. More...
 
const char * cnfnode_getname (const struct cnfnode *cn)
 gets the name of a node. More...
 
void cnfnode_setval (struct cnfnode *cn, const char *value)
 sets the value of a node. More...
 
void cnfnode_setname (struct cnfnode *cn, const char *name)
 sets the name of a node. More...
 
void destroy_cnfnode (struct cnfnode *cn)
 frees a node structure. More...
 
void destroy_cnftree (struct cnfnode *cn)
 frees a whole node tree. More...
 
void append_node (struct cnfnode *cn_parent, struct cnfnode *cn)
 appends a node to the list of children. More...
 
void insert_node_before (struct cnfnode *cn_before, struct cnfnode *cn)
 inserts a node to the list of children before another node. More...
 
void unlink_node (struct cnfnode *cn)
 unlink a node from its list. More...
 
struct cnfnodefind_node (struct cnfnode *cn_list, const char *name)
 search for a node. More...
 
int compare_cnfnode (const struct cnfnode *cn1, const struct cnfnode *cn2)
 compare two nodes. More...
 
int compare_cnftree (const struct cnfnode *cn_root1, const struct cnfnode *cn_root2)
 compare two trees. More...
 
int compare_cnftree_children (const struct cnfnode *cn_root1, const struct cnfnode *cn_root2)
 compare two trees. More...
 
void dump_nodes (struct cnfnode *cn_root, int level)
 

Function Documentation

◆ append_node()

void append_node ( struct cnfnode cn_parent,
struct cnfnode cn 
)

appends a node to the list of children.

Parameters
cn_parentthe parent node
cnpointer to the node to be appended

◆ clone_cnfnode()

struct cnfnode* clone_cnfnode ( const struct cnfnode cn)

copies a node.

a new node will be allocated, and the name and value of cn copied. The node will not be linked into the tree.

Parameters
cnthe pointer to the node to be copied
Returns
the pointer to the copied node

◆ clone_cnftree()

struct cnfnode* clone_cnftree ( const struct cnfnode cn_root)

copy a whole tree.

recursively copies a whole tree by calling clone_cnfnode()

Parameters
cn_rootpointer to the root of the tree.
Returns
the pointer to the root of the copied tree

◆ cnfnode_getname()

const char* cnfnode_getname ( const struct cnfnode cn)
inline

gets the name of a node.

Parameters
cnpointer to a node

◆ cnfnode_getval()

const char* cnfnode_getval ( const struct cnfnode cn)
inline

gets the value of a node.

Parameters
cnpointer to a node

◆ cnfnode_setname()

void cnfnode_setname ( struct cnfnode cn,
const char *  name 
)

sets the name of a node.

if the node already has a name, that name will be free'ed.

Parameters
cnpointer to a node
namepointer to the new name

◆ cnfnode_setval()

void cnfnode_setval ( struct cnfnode cn,
const char *  value 
)

sets the value of a node.

if the node already has a value, that value will be free'ed.

Parameters
cnpointer to a node
valuepointer to the new value

◆ compare_cnfnode()

int compare_cnfnode ( const struct cnfnode cn1,
const struct cnfnode cn2 
)

compare two nodes.

compares two nodes by name and then value. A NULL value is less than any string.

Parameters
cn1first node
cn2second node
Returns
0 if name and value match
-2 or 2 if the names do not match
-1 or 1 if the values do not match

◆ compare_cnftree()

int compare_cnftree ( const struct cnfnode cn_root1,
const struct cnfnode cn_root2 
)

compare two trees.

Recursively compare two trees if they are the same, by comparing the names, values and subtrees. The return value is pretty much useless, except for the fact that it indicates if the trees match or not, because this function returns as soon as it finds some difference.

Parameters
cn_root1the first tree
cn_root2the second tree
Returns
0 if names and values and children match
-3/3 if cn_root1 has less/more descendants than cn_root2
the result of compare_cnfnode() if names or values do not match
See also
compare_cnfnode

◆ compare_cnftree_children()

int compare_cnftree_children ( const struct cnfnode cn_root1,
const struct cnfnode cn_root2 
)

compare two trees.

Recursively compare two trees if they are the same, by comparing the names, values and subtrees, except the names and values of the two rot nodes. The return value is pretty much useless, except for the fact that it indicates if the trees match or not, because this function returns as soon as it finds some difference.

Parameters
cn_root1the first tree
cn_root2the second tree
Returns
0 if names and values and children match
-3/3 if cn_root1 has less/more descendants than cn_root2
the result of compare_cnfnode() if names or values do not match
See also
compare_cnfnode

◆ create_cnfnode()

struct cnfnode* create_cnfnode ( const char *  name)

creates an empty node.

a node will be allocated, and its name set. The allocated structure will be returned.

Parameters
namethe name of the node
Returns
the pointer to the new node

◆ destroy_cnfnode()

void destroy_cnfnode ( struct cnfnode cn)

frees a node structure.

the memory of the node structure will be freed. Any memory used by the name or value will be freed as well.

Parameters
cnpointer to a node

◆ destroy_cnftree()

void destroy_cnftree ( struct cnfnode cn_root)

frees a whole node tree.

recursively frees memory of the tree pointed to by cn, by recursively calling destroy_cnfnode()

Parameters
cn_rootpointer to the root of the tree.

◆ dump_nodes()

void dump_nodes ( struct cnfnode cn_root,
int  level 
)

◆ find_node()

struct cnfnode* find_node ( struct cnfnode cn_list,
const char *  name 
)

search for a node.

searches in the list beginning with cn_list. This function does not search recursively in the children's lists.

Parameters
cn_listthe first node to be searched
namethe name to search for
Returns
the pointer to the matching node

◆ insert_node_before()

void insert_node_before ( struct cnfnode cn_before,
struct cnfnode cn 
)

inserts a node to the list of children before another node.

Parameters
cn_beforepointer to the node before which the node shall be inserted.
cnpointer to the node to be inserted

◆ unlink_node()

void unlink_node ( struct cnfnode cn)

unlink a node from its list.

removes a node from its list. The memory will not be freed, you have to call destroy_cnfnode() or destroy_cnftree() separately.

Parameters
cnpointer to the node to be unlinked.