コード例 #1
0
ファイル: test-api.c プロジェクト: flebel/augeas
/* Check that defining a variable leads to a corresponding entry in
 * /augeas/variables and that that entry disappears when the variable is
 * undefined */
static void testDefVarMeta(CuTest *tc) {
    int r;
    struct augeas *aug;
    static const char *const expr = "/augeas/version/save/mode";
    const char *value;

    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
    CuAssertPtrNotNull(tc, aug);
    CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug));

    r = aug_defvar(aug, "var", expr);
    CuAssertIntEquals(tc, 4, r);

    r = aug_match(aug, "/augeas/variables/*", NULL);
    CuAssertIntEquals(tc, 1, r);

    r = aug_get(aug, "/augeas/variables/var", &value);
    CuAssertStrEquals(tc, expr, value);

    r = aug_defvar(aug, "var", NULL);
    CuAssertIntEquals(tc, 0, r);

    r = aug_match(aug, "/augeas/variables/*", NULL);
    CuAssertIntEquals(tc, 0, r);

    aug_close(aug);
}
コード例 #2
0
ファイル: test-api.c プロジェクト: flebel/augeas
/* Check that defining a variable with defnode leads to a corresponding
 * entry in /augeas/variables and that that entry disappears when the
 * variable is undefined
 */
static void testDefNodeCreateMeta(CuTest *tc) {
    int r, created;
    struct augeas *aug;
    static const char *const expr = "/augeas/version/save/mode[last()+1]";
    static const char *const expr_can = "/augeas/version/save/mode[5]";
    const char *value;

    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
    CuAssertPtrNotNull(tc, aug);
    CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug));

    r = aug_defnode(aug, "var", expr, "other", &created);
    CuAssertIntEquals(tc, 1, r);
    CuAssertIntEquals(tc, 1, created);

    r = aug_match(aug, "/augeas/variables/*", NULL);
    CuAssertIntEquals(tc, 1, r);

    r = aug_get(aug, "/augeas/variables/var", &value);
    CuAssertStrEquals(tc, expr_can, value);

    r = aug_defvar(aug, "var", NULL);
    CuAssertIntEquals(tc, 0, r);

    r = aug_match(aug, "/augeas/variables/*", NULL);
    CuAssertIntEquals(tc, 0, r);

    aug_close(aug);
}
コード例 #3
0
ファイル: dump.c プロジェクト: hercules-team/augeas
/*
 * Print out information for all nodes matching PATH using aug_ns_*
 * functions
 */
static void dump_var(struct augeas *aug, const char *path) {
    int nmatches;
    int i;

    /* Define the variable 'matches' to hold all the nodes we are
       interested in */
    aug_defvar(aug, "matches", path);

    /* Count how many nodes we have */
    nmatches = aug_match(aug, "$matches", NULL);
    if (nmatches < 0) {
        fprintf(stderr, "aug_match for '%s' failed\n", path);
        fprintf(stderr, "error: %s\n", aug_error_message(aug));
        exit(1);
    }

    fprintf(stderr, "using var and aug_ns_*\n");
    fprintf(stderr, "%d matches for %s\n", nmatches, path);

    for (i=0; i < nmatches; i++) {
        const char *value, *label;
        char *file = NULL;

        /* Get information about the ith node, equivalent to calling
         * aug_get etc. for "$matches[i]" but much more efficient internally
         */
        aug_ns_attr(aug, "matches", i, &value, &label, &file);

        printf("%d: %s %s %s\n", i, label, value, file);
        free(file);
    }
}
コード例 #4
0
ファイル: laugeas.c プロジェクト: ncopa/lua-augeas
static int Paug_defvar(lua_State *L)
{
    augeas *a = Paug_checkarg(L, 1);
    const char *name = luaL_checkstring(L, 2);
    const char *expr = luaL_checkstring(L, 3);
    return pushresult(L, aug_defvar(a, name, expr), a, NULL);
}
コード例 #5
0
ファイル: _augeas.c プロジェクト: Salzig/ruby-augeas
/*
 * call-seq:
 *   defvar(NAME, EXPR) -> boolean
 *
 * Define a variable NAME whose value is the result of evaluating EXPR. If
 * a variable NAME already exists, its name will be replaced with the
 * result of evaluating EXPR.
 *
 * If EXPR is NULL, the variable NAME will be removed if it is defined.
 *
 */
VALUE augeas_defvar(VALUE s, VALUE name, VALUE expr) {
    augeas *aug = aug_handle(s);
    const char *cname = StringValueCStr(name);
    const char *cexpr = StringValueCStrOrNull(expr);

    int r = aug_defvar(aug, cname, cexpr);

    return (r < 0) ? Qfalse : Qtrue;
}
コード例 #6
0
ファイル: augeas.c プロジェクト: gaowanlong/libguestfs
int
do_aug_defvar (const char *name, const char *expr)
{
#ifdef HAVE_AUG_DEFVAR
  int r;

  NEED_AUG (-1);

  r = aug_defvar (aug, name, expr);
  if (r == -1) {
    reply_with_error ("Augeas defvar failed");
    return -1;
  }
  return r;
#else
  NOT_AVAILABLE (-1);
#endif
}