[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - Tree functions to find/create a node with a path expression



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=d2a4672a9178d00194664a5e596894c242dd46c7
Commit:        d2a4672a9178d00194664a5e596894c242dd46c7
Parent:        41fd642104b7e254c6ff950dc30d1dd0afcf61a9
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Thu Jan 7 11:17:57 2010 -0800
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Thu Jan 7 11:45:04 2010 -0800

Tree functions to find/create a node with a path expression

Internal counterparts to aug_get and aug_set

  * src/internal.h (tree_find, tree_find_cr): new prototypes
  * src/augeas.c (tree_find, tree_find_cr): new functions
---
 src/augeas.c   |   35 +++++++++++++++++++++++++++++++++++
 src/internal.h |   11 +++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index 1fb7842..2f4b788 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -120,6 +120,41 @@ struct tree *tree_path_cr(struct tree *tree, int n, ...) {
     return tree;
 }
 
+struct tree *tree_find(struct augeas *aug, const char *path) {
+    struct pathx *p = NULL;
+    struct tree *result = NULL;
+    int r;
+
+    pathx_parse(aug->origin, aug->error, path, true, aug->symtab, &p);
+    ERR_BAIL(aug);
+
+    r = pathx_find_one(p, &result);
+    BUG_ON(r > 1, aug,
+           "Multiple matches for %s when only one was expected",
+           path);
+ done:
+    free_pathx(p);
+    return result;
+ error:
+    result = NULL;
+    goto done;
+}
+
+struct tree *tree_find_cr(struct augeas *aug, const char *path) {
+    struct pathx *p = NULL;
+    struct tree *result = NULL;
+    int r;
+
+    pathx_parse(aug->origin, aug->error, path, true, aug->symtab, &p);
+    ERR_BAIL(aug);
+
+    r = pathx_expand_tree(p, &result);
+    ERR_BAIL(aug);
+ error:
+    free_pathx(p);
+    return result;
+}
+
 int tree_set_value(struct tree *tree, const char *value) {
     if (tree->value != NULL) {
         free(tree->value);
diff --git a/src/internal.h b/src/internal.h
index 5189a83..7daa43a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -388,6 +388,17 @@ struct tree *tree_path_cr(struct tree *tree, int n, ...);
 int tree_set_value(struct tree *tree, const char *value);
 /* Cleanly remove all children of TREE, but leave TREE itself unchanged */
 void tree_unlink_children(struct augeas *aug, struct tree *tree);
+/* Find the node matching PATH.
+ * Returns the node or NULL on error
+ * Errors: EMMATCH - more than one node matches PATH
+ *         ENOMEM  - allocation error
+ */
+struct tree *tree_find(struct augeas *aug, const char *path);
+/* Find the node matching PATH. Expand the tree to contain such a node if
+ * none exists.
+ * Returns the node or NULL on error
+ */
+struct tree *tree_find_cr(struct augeas *aug, const char *path);
 
 /* Struct: memstream
  * Wrappers to simulate OPEN_MEMSTREAM where that's not available. The



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]