[augeas-devel] Difference between API's aug_match and augtool's match

Raphaël Pinson raphink at gmail.com
Thu Sep 4 12:29:36 UTC 2008


On Thu, Sep 4, 2008 at 12:38 PM, Free Ekanayaka <free at 64studio.com> wrote:

> Hi,
>
> the match command from augtool allows get select paths matching a
> certain value:
>
>    match <PATH> [<VALUE>]
>        Find all paths that match the path expression PATH. If VALUE is
> given,
>        only the matching paths whose value equals VALUE are printed
>
>
> However the aug_match function doesn't seem to support values, at
> least according to the documentation at
>
> http://augeas.net/docs/api.html
>
> Would it be possible to support values in the API as well?
>


>From augtool.c

static int cmd_match(char *args[]) {
    int cnt;
    const char *pattern = cleanpath(args[0]);
    char **matches;
    int filter = (args[1] != NULL) && (strlen(args[1]) > 0);

    cnt = aug_match(aug, pattern, &matches);
    if (cnt == -1) {
        printf("  (error matching %s)\n", pattern);
        return -1;
    }
    if (cnt == 0) {
        printf("  (no matches)\n");
        return 0;
    }

    for (int i=0; i < cnt; i++) {
        const char *val;
        aug_get(aug, matches[i], &val);
        if (val == NULL)
            val = "(none)";
        if (filter) {
            if (STREQ(args[1], val))
                printf("%s\n", matches[i]);
        } else {
            printf("%s = %s\n", matches[i], val);
        }
        free((void *) matches[i]);
    }
    free(matches);
    return 0;
}



In essence, the match command in augtool does first a aug_match call, and
then goes through the results and does an aug_get on each node and checks
that the value matches the given (optional) string (it would actually be
interesting if augtool accepted a regexp as a filter by the way).

This cannot be added to the API without modifying the API, which is not
acceptable, so you'd have to either rewrite what cmd_match does in your
program, or make a new API call (e.g. aug_match_filter) that would do this.


Raphaël
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080904/e457ca06/attachment.htm>


More information about the augeas-devel mailing list