[augeas-devel] [PATCH 7/7] Simpler interface and implementation for path_find_one

David Lutterkort lutter at redhat.com
Mon Dec 22 19:46:33 UTC 2008


---
 src/augeas.c   |    8 ++++----
 src/internal.h |    2 +-
 src/pathx.c    |   15 +++++++++++++--
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/augeas.c b/src/augeas.c
index ee4ef23..4d61ffc 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -229,7 +229,7 @@ int aug_get(const struct augeas *aug, const char *path, const char **value) {
     if (value != NULL)
         *value = NULL;
 
-    r = path_find_one(p, &match, NULL);
+    r = path_find_one(p, &match);
     if (r == 1 && value != NULL)
         *value = match->value;
     free_path(p);
@@ -284,7 +284,7 @@ int tree_insert(struct tree *origin, const char *path, const char *label,
     if (p == NULL)
         goto error;
 
-    if (path_find_one(p, &match, NULL) != 1)
+    if (path_find_one(p, &match) != 1)
         goto error;
 
     new = make_tree(strdup(label), NULL, match->parent, NULL);
@@ -447,7 +447,7 @@ int aug_mv(struct augeas *aug, const char *src, const char *dst) {
     if (s == NULL || d == NULL)
         goto done;
 
-    r = path_find_one(s, &ts, NULL);
+    r = path_find_one(s, &ts);
     if (r != 1)
         goto done;
 
@@ -607,7 +607,7 @@ int aug_save(struct augeas *aug) {
     struct tree *files;
     struct path *p = make_path(aug->origin->children, AUGEAS_FILES_TREE);
 
-    if (p == NULL || path_find_one(p, &files, NULL) != 1) {
+    if (p == NULL || path_find_one(p, &files) != 1) {
         free_path(p);
         return -1;
     }
diff --git a/src/internal.h b/src/internal.h
index a577ad6..da0a501 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -339,7 +339,7 @@ struct path;
 struct path *make_path(const struct tree *root, const char *path);
 struct tree *path_first(struct path *path);
 struct tree *path_next(struct path *path, struct tree *cur);
-int path_find_one(struct path *path, struct tree **match, int *segnr);
+int path_find_one(struct path *path, struct tree **match);
 int path_expand_tree(struct path *path, struct tree **tree);
 void free_path(struct path *path);
 
diff --git a/src/pathx.c b/src/pathx.c
index 7ee3ec1..90c5504 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -253,7 +253,7 @@ struct tree *path_first(struct path *path) {
  * number of the segment in PATH where MATCH matched. If no node matches,
  * MATCH will be NULL, and SEGNR -1
  */
-int path_find_one(struct path *path, struct tree **match, int *segnr) {
+static int path_search(struct path *path, struct tree **match, int *segnr) {
     struct tree **matches = NULL;
     int *nmatches = NULL;
     int result;
@@ -327,7 +327,7 @@ int path_expand_tree(struct path *path, struct tree **tree) {
     int r, segnr;
 
     *tree = path->root;
-    r = path_find_one(path, tree, &segnr);
+    r = path_search(path, tree, &segnr);
     if (r == -1)
         return -1;
 
@@ -364,6 +364,17 @@ int path_expand_tree(struct path *path, struct tree **tree) {
     return -1;
 }
 
+int path_find_one(struct path *path, struct tree **tree) {
+    *tree = path_first(path);
+    if (*tree == NULL)
+        return 0;
+
+    if (path_next(path, *tree) != NULL) {
+        *tree = NULL;
+        return -1;
+    }
+    return 1;
+}
 /*
  * Local variables:
  *  indent-tabs-mode: nil
-- 
1.6.0.4




More information about the augeas-devel mailing list