[augeas-devel] [PATCH 05/11] Simplify internal API's
David Lutterkort
lutter at redhat.com
Mon Jan 26 05:41:18 UTC 2009
* pass origin, not root to pathx_parse
* pathx_next does not need an explicit argument for the current
tree node any more
---
src/augeas.c | 38 +++++++++++++++++++-------------------
src/builtin.c | 4 ++--
src/internal.h | 8 ++++----
src/pathx.c | 10 +++-------
src/syntax.c | 2 +-
5 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 69a9baf..7586ee7 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -236,7 +236,7 @@ int aug_get(const struct augeas *aug, const char *path, const char **value) {
struct tree *match;
int r;
- if (pathx_parse(aug->origin->children, path, &p) != 0)
+ if (pathx_parse(aug->origin, path, &p) != 0)
return -1;
if (value != NULL)
@@ -250,12 +250,13 @@ int aug_get(const struct augeas *aug, const char *path, const char **value) {
return r;
}
-struct tree *tree_set(struct tree *root, const char *path, const char *value) {
+struct tree *tree_set(struct tree *origin, const char *path,
+ const char *value) {
struct tree *tree;
struct pathx *p;
int r;
- if (pathx_parse(root, path, &p) != 0)
+ if (pathx_parse(origin, path, &p) != 0)
goto error;
r = pathx_expand_tree(p, &tree);
@@ -280,7 +281,7 @@ struct tree *tree_set(struct tree *root, const char *path, const char *value) {
}
int aug_set(struct augeas *aug, const char *path, const char *value) {
- return tree_set(aug->origin->children, path, value) == NULL ? -1 : 0;
+ return tree_set(aug->origin, path, value) == NULL ? -1 : 0;
}
int tree_insert(struct tree *origin, const char *path, const char *label,
@@ -293,7 +294,7 @@ int tree_insert(struct tree *origin, const char *path, const char *label,
if (strchr(label, SEP) != NULL)
return -1;
- if (pathx_parse(origin->children, path, &p) != 0)
+ if (pathx_parse(origin, path, &p) != 0)
goto error;
if (pathx_find_one(p, &match) != 1)
@@ -380,14 +381,13 @@ int tree_rm(struct tree *origin, const char *path) {
assert(origin->next == NULL);
struct pathx *p = NULL;
- struct tree *root = origin->children;
struct tree *tree, **del;
int cnt = 0, ndel = 0, i;
- if (pathx_parse(root, path, &p) != 0)
+ if (pathx_parse(origin, path, &p) != 0)
return -1;
- for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p, tree)) {
+ for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p)) {
if (! TREE_HIDDEN(tree))
ndel += 1;
}
@@ -402,7 +402,7 @@ int tree_rm(struct tree *origin, const char *path) {
return -1;
}
- for (i = 0, tree = pathx_first(p); tree != NULL; tree = pathx_next(p, tree)) {
+ for (i = 0, tree = pathx_first(p); tree != NULL; tree = pathx_next(p)) {
if (TREE_HIDDEN(tree))
continue;
del[i] = tree;
@@ -434,7 +434,7 @@ int aug_tree_replace(struct augeas *aug, const char *path, struct tree *sub) {
if (r == -1)
goto error;
- parent = tree_set(aug->origin->children, path, NULL);
+ parent = tree_set(aug->origin, path, NULL);
if (parent == NULL)
goto error;
@@ -448,13 +448,13 @@ int aug_tree_replace(struct augeas *aug, const char *path, struct tree *sub) {
}
int aug_mv(struct augeas *aug, const char *src, const char *dst) {
- struct tree *root = aug->origin->children;
struct pathx *s, *d;
struct tree *ts, *td, *t;
int r, ret;
ret = -1;
- if (pathx_parse(root, src, &s) != 0 || pathx_parse(root, dst, &d) != 0)
+ if (pathx_parse(aug->origin, src, &s) != 0
+ || pathx_parse(aug->origin, dst, &d) != 0)
goto done;
r = pathx_find_one(s, &ts);
@@ -512,10 +512,10 @@ int aug_match(const struct augeas *aug, const char *pathin, char ***matches) {
pathin = "/*";
}
- if (pathx_parse(aug->origin->children, pathin, &p) != 0)
+ if (pathx_parse(aug->origin, pathin, &p) != 0)
return -1;
- for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p, tree)) {
+ for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p)) {
if (! TREE_HIDDEN(tree))
cnt += 1;
}
@@ -529,10 +529,10 @@ int aug_match(const struct augeas *aug, const char *pathin, char ***matches) {
if (*matches == NULL)
goto error;
- pathx_parse(aug->origin->children, pathin, &p);
+ pathx_parse(aug->origin, pathin, &p);
int i = 0;
- for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p, tree)) {
+ for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p)) {
if (TREE_HIDDEN(tree))
continue;
(*matches)[i] = format_path(tree);
@@ -644,7 +644,7 @@ int aug_save(struct augeas *aug) {
if (update_save_flags(aug) < 0)
return -1;
- if (pathx_parse(aug->origin->children, AUGEAS_FILES_TREE, &p) != 0)
+ if (pathx_parse(aug->origin, AUGEAS_FILES_TREE, &p) != 0)
return -1;
if (pathx_find_one(p, &files) != 1) {
free_pathx(p);
@@ -727,7 +727,7 @@ int print_tree(const struct tree *start, FILE *out, const char *pathin,
if (pathx_parse(start, pathin, &p) != 0)
return -1;
- for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p, tree)) {
+ for (tree = pathx_first(p); tree != NULL; tree = pathx_next(p)) {
if (TREE_HIDDEN(tree) && ! pr_hidden)
continue;
@@ -754,7 +754,7 @@ int aug_print(const struct augeas *aug, FILE *out, const char *pathin) {
if (pathin == NULL || strlen(pathin) == 0) {
pathin = "/*";
}
- return print_tree(aug->origin->children, out, pathin, 0);
+ return print_tree(aug->origin, out, pathin, 0);
}
void aug_close(struct augeas *aug) {
diff --git a/src/builtin.c b/src/builtin.c
index e5c475a..05aeefc 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -134,7 +134,7 @@ static struct value *lens_get(struct info *info, struct value *l,
v = make_exn_lns_error(info, err, text);
if (tree != NULL) {
exn_printf_line(v, "Tree generated so far:");
- exn_print_tree(v, tree->children);
+ exn_print_tree(v, tree);
free_tree(tree);
}
free_lns_error(err);
@@ -187,7 +187,7 @@ static struct value *tree_set_glue(struct info *info, struct value *path,
fake = tree->origin->children;
}
- if (tree_set(tree->origin->children, path->string->str,
+ if (tree_set(tree->origin, path->string->str,
val->string->str) == NULL) {
return make_exn_value(ref(info),
"Tree set of %s to '%s' failed",
diff --git a/src/internal.h b/src/internal.h
index c201970..57be267 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -307,11 +307,11 @@ struct tree *make_tree_origin(struct tree *root);
int aug_tree_replace(struct augeas *aug, const char *path, struct tree *sub);
int tree_rm(struct tree *origin, const char *path);
-struct tree *tree_set(struct tree *tree, const char *path, const char *value);
+struct tree *tree_set(struct tree *origin, const char *path, const char *value);
int tree_insert(struct tree *origin, const char *path, const char *label,
int before);
int free_tree(struct tree *tree);
-int print_tree(const struct tree *tree, FILE *out, const char *path,
+int print_tree(const struct tree *origin, FILE *out, const char *path,
int pr_hidden);
int tree_equal(const struct tree *t1, const struct tree *t2);
@@ -368,9 +368,9 @@ struct pathx;
const char *pathx_error(struct pathx *pathx, const char **txt, int *pos);
-int pathx_parse(const struct tree *root, const char *path, struct pathx **px);
+int pathx_parse(const struct tree *origin, const char *path, struct pathx **px);
struct tree *pathx_first(struct pathx *path);
-struct tree *pathx_next(struct pathx *path, struct tree *cur);
+struct tree *pathx_next(struct pathx *path);
int pathx_find_one(struct pathx *path, struct tree **match);
int pathx_expand_tree(struct pathx *path, struct tree **tree);
void free_pathx(struct pathx *path);
diff --git a/src/pathx.c b/src/pathx.c
index 2461a8a..91ceeda 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -1255,8 +1255,7 @@ int pathx_parse(const struct tree *tree, const char *txt,
if (ALLOC(*pathx) < 0)
return PATHX_ENOMEM;
- if (tree != NULL)
- (*pathx)->origin = (struct tree *) tree->parent;
+ (*pathx)->origin = (struct tree *) tree;
/* Set up state */
if (ALLOC((*pathx)->state) < 0) {
@@ -1482,8 +1481,7 @@ static struct tree *locpath_next(struct locpath *lp, struct state *state) {
return complete_path(lp->last, state);
}
-struct tree *pathx_next(struct pathx *pathx,
- ATTRIBUTE_UNUSED struct tree *cur) {
+struct tree *pathx_next(struct pathx *pathx) {
return locpath_next(pathx->locpath, pathx->state);
}
@@ -1494,8 +1492,6 @@ static struct tree *locpath_first(struct locpath *lp, struct state *state) {
/* Find the first node in TREE matching PATH. */
struct tree *pathx_first(struct pathx *pathx) {
- if (pathx->origin == NULL)
- return NULL;
pathx->locpath->ctx = pathx->origin;
return locpath_first(pathx->locpath, pathx->state);
}
@@ -1644,7 +1640,7 @@ int pathx_find_one(struct pathx *path, struct tree **tree) {
if (*tree == NULL)
return 0;
- if (pathx_next(path, *tree) != NULL) {
+ if (pathx_next(path) != NULL) {
*tree = NULL;
return -1;
}
diff --git a/src/syntax.c b/src/syntax.c
index 3dc3019..eb05a4f 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -625,7 +625,7 @@ static void print_value(FILE *out, struct value *v) {
fprintf(out, ">");
break;
case V_TREE:
- print_tree(v->origin->children, stdout, "/*" , 1);
+ print_tree(v->origin, stdout, "/*" , 1);
break;
case V_FILTER:
fprintf(out, "<filter:");
--
1.6.0.6
More information about the augeas-devel
mailing list