[augeas-devel] augeas: master - * src/pathx.c (pathx_eval): factor eval into a function

David Lutterkort lutter at fedoraproject.org
Tue Mar 24 23:07:31 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=4a48a085dc65c4000d091f5dc6aa4439b2556237
Commit:        4a48a085dc65c4000d091f5dc6aa4439b2556237
Parent:        98ed9a1790b2ba529c260732a74165003f3668fa
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Fri Mar 20 17:03:59 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Sat Mar 21 20:41:26 2009 -0700

* src/pathx.c (pathx_eval): factor eval into a function

---
 src/pathx.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/pathx.c b/src/pathx.c
index 332aee1..d557902 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -1715,6 +1715,22 @@ static struct tree *step_next(struct step *step, struct tree *ctx,
     return node;
 }
 
+static struct value *pathx_eval(struct pathx *pathx) {
+    struct state *state = pathx->state;
+    state->ctx = pathx->origin;
+    state->ctx_pos = 1;
+    state->ctx_len = 1;
+    eval_expr(state->exprs[0], state);
+    if (HAS_ERROR(state))
+        return NULL;
+
+    if (state->values_used != 1) {
+        STATE_ERROR(state, PATHX_EINTERNAL);
+        return NULL;
+    }
+    return pop_value(state);
+}
+
 struct tree *pathx_next(struct pathx *pathx) {
     if (pathx->node + 1 < pathx->nodeset->used)
         return pathx->nodeset->nodes[++pathx->node];
@@ -1724,20 +1740,11 @@ struct tree *pathx_next(struct pathx *pathx) {
 /* Find the first node in TREE matching PATH. */
 struct tree *pathx_first(struct pathx *pathx) {
     if (pathx->nodeset == NULL) {
-        /* Evaluate */
-        struct state *state = pathx->state;
-        state->ctx = pathx->origin;
-        state->ctx_pos = 1;
-        state->ctx_len = 1;
-        eval_expr(state->exprs[0], state);
-        if (HAS_ERROR(state))
-            return NULL;
+        struct value *v = pathx_eval(pathx);
 
-        if (state->values_used != 1) {
-            STATE_ERROR(state, PATHX_EINTERNAL);
+        if (HAS_ERROR(pathx->state))
             return NULL;
-        }
-        pathx->nodeset = pop_value(state)->nodeset;
+        pathx->nodeset = v->nodeset;
     }
     pathx->node = 0;
     if (pathx->nodeset->used == 0)




More information about the augeas-devel mailing list