~ubuntu-branches/ubuntu/natty/augeas/natty

« back to all changes in this revision

Viewing changes to src/pathx.c

  • Committer: Bazaar Package Importer
  • Author(s): Raphaël Pinson
  • Date: 2011-02-24 09:32:22 UTC
  • mfrom: (1.2.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20110224093222-bfd4fkm6envek6ys
Tags: 0.8.0-0ubuntu1
* New upstream release.
* Remove obsolete ruby Build-Depend.
* Build PDF docs and add them to augeas-doc.
* Build-Depend on texlive-latex-base to build PDF docs.
* Install txt doc files in augeas-doc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
    pathx_errcode_t errcode;
211
211
    const char     *file;
212
212
    int             line;
 
213
    char           *errmsg;
213
214
 
214
215
    const char     *txt;  /* Entire expression */
215
216
    const char     *pos;  /* Current position within TXT during parsing */
504
505
        state->value_pool_size = new_size;
505
506
    }
506
507
    state->value_pool[state->value_pool_used].tag = tag;
 
508
    state->value_pool[state->value_pool_used].nodeset = NULL;
507
509
    return state->value_pool_used++;
508
510
}
509
511
 
629
631
 
630
632
static void func_regexp(struct state *state) {
631
633
    value_ind_t vind = make_value(T_REGEXP, state);
 
634
    int r;
632
635
 
633
636
    CHECK_ERROR;
634
637
 
642
645
    }
643
646
 
644
647
    struct regexp *rx = make_regexp(NULL, pat, 0);
 
648
    state->value_pool[vind].regexp = rx;
645
649
    if (rx == NULL) {
646
650
        FREE(pat);
647
651
        STATE_ENOMEM;
648
652
        return;
649
653
    }
650
 
    if (regexp_compile(rx) < 0) {
 
654
    r = regexp_compile(rx);
 
655
    if (r < 0) {
 
656
        const char *msg;
 
657
        regexp_check(rx, &msg);
 
658
        state->errmsg = strdup(msg);
651
659
        STATE_ERROR(state, PATHX_EREGEXP);
652
 
        unref(rx, regexp);
653
660
        return;
654
661
    }
655
 
    state->value_pool[vind].regexp = rx;
656
662
    push_value(vind, state);
657
663
}
658
664
 
674
680
        return true;
675
681
    default:
676
682
        assert(0);
 
683
        return false;
677
684
    }
678
 
    assert(0);
679
685
}
680
686
 
681
687
static int calc_eq_nodeset_nodeset(struct nodeset *ns1, struct nodeset *ns2,
932
938
        return v->nodeset->used > 0;
933
939
    default:
934
940
        assert(0);
 
941
        return false;
935
942
    }
936
943
}
937
944
 
2032
2039
    const pathx_errcode_t errcode = pathx->state->errcode;
2033
2040
    struct error *err = pathx->state->error;
2034
2041
 
2035
 
    char *pos_str = NULL;
 
2042
    char *pos_str = pathx->state->errmsg;
 
2043
    pathx->state->errmsg = NULL;
 
2044
 
 
2045
    if (err == NULL || errcode == PATHX_NOERROR || err->code != AUG_NOERROR)
 
2046
        return;
 
2047
 
2036
2048
    int pos;
2037
 
 
2038
 
    if (err == NULL || errcode == PATHX_NOERROR || err->code != AUG_NOERROR)
2039
 
        return;
2040
 
 
2041
2049
    pathx_msg = pathx_error(pathx, NULL, &pos);
2042
2050
 
2043
 
    if (ALLOC_N(pos_str, strlen(path) + 4) >= 0) {
2044
 
        strncpy(pos_str, path, pos);
 
2051
    bool has_msg = pos_str != NULL;
 
2052
    int pos_str_len = pos_str == NULL ? 0 : strlen(pos_str);
 
2053
    if (REALLOC_N(pos_str, pos_str_len + strlen(path) + 8) >= 0) {
 
2054
        if (has_msg) {
 
2055
            strcat(pos_str, " in ");
 
2056
            strncat(pos_str, path, pos);
 
2057
        } else {
 
2058
            /* initialize pos_str explicitly, path might be "" */
 
2059
            pos_str[0] = '\0';
 
2060
            strncat(pos_str, path, pos);
 
2061
        }
2045
2062
        strcat(pos_str, "|=|");
2046
2063
        strcat(pos_str, path + pos);
2047
2064
    }
2051
2068
    err->details = pos_str;
2052
2069
    pos_str = NULL;
2053
2070
    err->minor_details = pathx_msg;
2054
 
 
2055
 
    FREE(pos_str);
2056
2071
}
2057
2072
 
2058
2073
int pathx_parse(const struct tree *tree,
2076
2091
    state = (*pathx)->state;
2077
2092
 
2078
2093
    state->errcode = PATHX_NOERROR;
 
2094
    state->errmsg = NULL;
2079
2095
    state->txt = txt;
2080
2096
    state->pos = txt;
2081
2097
    state->symtab = symtab;