[augeas-devel] [PATCH 07/11] * src/pathx.c (pathx_parse): new parameter need_nodeset
David Lutterkort
lutter at redhat.com
Mon Mar 23 06:27:32 UTC 2009
---
src/augeas.c | 8 ++++----
src/builtin.c | 9 ++++++---
src/internal.h | 13 ++++++++++++-
src/pathx.c | 5 +++--
src/transform.c | 2 +-
5 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/augeas.c b/src/augeas.c
index 60460ba..fa50de8 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -125,7 +125,7 @@ static struct pathx *parse_user_pathx(const struct augeas *aug,
struct pathx *result;
int pos;
- if (pathx_parse(aug->origin, path, &result) == PATHX_NOERROR)
+ if (pathx_parse(aug->origin, path, true, &result) == PATHX_NOERROR)
return result;
struct tree *error =
@@ -545,7 +545,7 @@ int tree_replace(struct tree *origin, const char *path, struct tree *sub) {
struct pathx *p = NULL;
int r;
- if (pathx_parse(origin, path, &p) != PATHX_NOERROR)
+ if (pathx_parse(origin, path, true, &p) != PATHX_NOERROR)
goto error;
r = tree_rm(p);
@@ -761,7 +761,7 @@ static int unlink_removed_files(struct augeas *aug,
if (tf == NULL) {
/* Unlink all files in tm */
struct pathx *px = NULL;
- if (pathx_parse(tm, file_nodes, &px)
+ if (pathx_parse(tm, file_nodes, true, &px)
!= PATHX_NOERROR) {
result = -1;
continue;
@@ -895,7 +895,7 @@ int dump_tree(FILE *out, struct tree *tree) {
struct pathx *p;
int result;
- if (pathx_parse(tree, "/*", &p) != PATHX_NOERROR)
+ if (pathx_parse(tree, "/*", true, &p) != PATHX_NOERROR)
return -1;
result = print_tree(out, p, 1);
diff --git a/src/builtin.c b/src/builtin.c
index f0f5442..e256fa7 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -212,7 +212,8 @@ static struct value *tree_set_glue(struct info *info, struct value *path,
fake = tree->origin->children;
}
- if (pathx_parse(tree->origin, path->string->str, &p) != PATHX_NOERROR) {
+ if (pathx_parse(tree->origin, path->string->str, true, &p)
+ != PATHX_NOERROR) {
result = make_pathx_exn(ref(info), p);
goto done;
}
@@ -248,7 +249,8 @@ static struct value *tree_insert_glue(struct info *info, struct value *label,
struct pathx *p = NULL;
struct value *result = NULL;
- if (pathx_parse(tree->origin, path->string->str, &p) != PATHX_NOERROR) {
+ if (pathx_parse(tree->origin, path->string->str, true, &p)
+ != PATHX_NOERROR) {
result = make_pathx_exn(ref(info), p);
goto done;
}
@@ -294,7 +296,8 @@ static struct value *tree_rm_glue(struct info *info,
struct pathx *p = NULL;
struct value *result = NULL;
- if (pathx_parse(tree->origin, path->string->str, &p) != PATHX_NOERROR) {
+ if (pathx_parse(tree->origin, path->string->str, true, &p)
+ != PATHX_NOERROR) {
result = make_pathx_exn(ref(info), p);
goto done;
}
diff --git a/src/internal.h b/src/internal.h
index 407f184..d9d0e60 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -30,6 +30,7 @@
#include <string.h>
#include <strings.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
@@ -389,7 +390,17 @@ struct pathx;
const char *pathx_error(struct pathx *pathx, const char **txt, int *pos);
-int pathx_parse(const struct tree *origin, const char *path, struct pathx **px);
+/* Parse the string PATH into a path expression PX that will be evaluated
+ * against the tree ORIGIN.
+ *
+ * If NEED_NODESET is true, the resulting path expression must evaluate toa
+ * nodeset, otherwise it can evaluate to a value of any type.
+ *
+ * Returns 0 on success, and -1 on error
+ */
+int pathx_parse(const struct tree *origin, const char *path,
+ bool need_nodeset,
+ struct pathx **px);
struct tree *pathx_first(struct pathx *path);
struct tree *pathx_next(struct pathx *path);
int pathx_find_one(struct pathx *path, struct tree **match);
diff --git a/src/pathx.c b/src/pathx.c
index cc87713..b4da423 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -1664,7 +1664,7 @@ static void parse_expr(struct state *state) {
}
int pathx_parse(const struct tree *tree, const char *txt,
- struct pathx **pathx) {
+ bool need_nodeset, struct pathx **pathx) {
struct state *state = NULL;
*pathx = NULL;
@@ -1716,7 +1716,7 @@ int pathx_parse(const struct tree *tree, const char *txt,
if (HAS_ERROR(state))
goto done;
- if (state->exprs[0]->type != T_NODESET) {
+ if (need_nodeset && state->exprs[0]->type != T_NODESET) {
STATE_ERROR(state, PATHX_ETYPE);
goto done;
}
@@ -1834,6 +1834,7 @@ struct tree *pathx_first(struct pathx *pathx) {
if (HAS_ERROR(pathx->state))
return NULL;
+ assert(v->tag == T_NODESET);
pathx->nodeset = v->nodeset;
}
pathx->node = 0;
diff --git a/src/transform.c b/src/transform.c
index 2675f23..92cdc8f 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -654,7 +654,7 @@ static int file_saved_event(struct augeas *aug, const char *path) {
struct tree *dummy;
int r;
- r = pathx_parse(aug->origin, AUGEAS_EVENTS_SAVED "[last()]", &px);
+ r = pathx_parse(aug->origin, AUGEAS_EVENTS_SAVED "[last()]", true, &px);
if (r != PATHX_NOERROR)
return -1;
--
1.6.0.6
More information about the augeas-devel
mailing list