llconf 0.0.2
|
High level functions to access a cnfnode tree. More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "strutils.h"
#include "nodes.h"
#include "entry.h"
Macros | |
#define | FIND_ENTRY_FLAG_NOPATH 0x01 |
#define | FIND_ENTRY_FLAG_FIRST 0x02 |
Functions | |
struct cnfresult * | create_cnfresult (struct cnfnode *cn, const char *path) |
Create a cnfresult structure. | |
void | destroy_cnfresult (struct cnfresult *cr) |
Free a single cnfresult element. | |
void | destroy_cnfresult_list (struct cnfresult *cr_list) |
Free a cnfresult structure list by calling destroy_cnfresult() for all list members. | |
void | append_cnfresult (struct cnfresult *cr_first, struct cnfresult *cr) |
Append a cnfresult to the list. | |
struct cnfresult * | cnf_find_entry (struct cnfnode *cn_root, const char *path) |
Find all matching entries in a tree. | |
struct cnfnode * | cnf_add_branch (struct cnfnode *cn_root, const char *path, int do_merge) |
Add a branch to a tree. | |
int | cnf_del_branch (struct cnfnode *cn_root, const char *path, int del_empty) |
Delete a branch of the tree. | |
int | cnf_set_entry (struct cnfnode *cn_root, const char *path, const char *val, int do_create) |
Set the value of a single entry in the tree. | |
const char * | cnf_get_entry (struct cnfnode *cn_root, const char *path) |
Get the value of a single entry in the tree. | |
struct cnfnode * | cnf_get_node (struct cnfnode *cn_root, const char *path) |
Get a pointer to a single node in the tree. | |
void | strip_cnftree (struct cnfnode *cn_root) |
Strip comments and empty lines from the tree. | |
High level functions to access a cnfnode tree.
Functions here provide a higher level access to the cnfnode tree than the cnfnode_* functions from node.c. They usually handle with path names and values, rather than pointers to the nodes.
#define FIND_ENTRY_FLAG_FIRST 0x02 |
#define FIND_ENTRY_FLAG_NOPATH 0x01 |
Append a cnfresult to the list.
[in] | cr_first | the first entry in the list |
[in] | cr | the entry to be appended |
Add a branch to a tree.
Add a branch to an existing tree of nodes. If part of the tree already exists, and do_merge==1, the remainder will be created. For example, if path is "iface/eth0/address", and "iface/eth0" already exists and do_merge==1, just "address" will be appended to "iface/eth0". If do_merge==0, a whole new subtree, starting with "iface" will be appended.
[in] | cn_root | pointer to the root of the tree |
[in] | path | the path to append to |
[in] | do_merge | flag as described above |
int cnf_del_branch | ( | struct cnfnode * | cn_root, |
const char * | path, | ||
int | del_empty ) |
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.
[in] | cn_root | pointer to the root of the tree |
[in] | path | the path of the tree to be deleted |
[in] | del_empty | set to 1 if empty parents shall be removed. |
Find all matching entries in a tree.
Search in the cnfnode tree for entries matching the given path specification.
[in] | cn_root | The root of the cnfnode tree |
[in] | path | A string specifying the path to be sought. |
const char * cnf_get_entry | ( | struct cnfnode * | cn_root, |
const char * | path ) |
Get the value of a single entry in the tree.
Get the value of an entry pointed to by path.
[in] | cn_root | A pointer to the root of the tree. |
[in] | path | the path of the entry. |
Get a pointer to a single node in the tree.
Get the node of an entry pointed to by path. If more than one matching entry exists, the first one will be returned.
[in] | cn_root | A pointer to the root of the tree. |
[in] | path | The path to seek. |
int cnf_set_entry | ( | struct cnfnode * | cn_root, |
const char * | path, | ||
const char * | val, | ||
int | do_create ) |
Set the value of a single entry in the tree.
Set the value of an entry pointed to by path. If more than one matching entry exists, the first one will be set. If do_create==1, a new node (or subtree) will be created, if the entry does not exist. if do_create==0, -1 will be returned, and errno will be set to ENOENT.
[in] | cn_root | pointer to the root of the tree |
[in] | path | the path of the entry |
[in] | val | the (new) value of the entry |
[in] | do_create | flag as described above |
void destroy_cnfresult | ( | struct cnfresult * | cr | ) |
Free a single cnfresult element.
[in] | cr | The structure to free. |
void destroy_cnfresult_list | ( | struct cnfresult * | cr_list | ) |
Free a cnfresult structure list by calling destroy_cnfresult() for all list members.
[in] | cr_list | pointer to the cnfresult list to destroy. |
void strip_cnftree | ( | struct cnfnode * | cn_root | ) |
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 .comment
, .empty
or .unparsed
nodes, for example.
[in] | cn_root | A pointer to the root of the tree which is to be stripped. |