Пример #1
0
/*
 * Look for a possible callback for a newly added variable
 * This is called specifically when the variable did not exist in the hash
 * previously, so the blanket update did not find this variable.
 */
void env_callback_init(ENTRY *var_entry)
{
	const char *var_name = var_entry->key;
	char callback_name[256] = "";
	struct env_clbk_tbl *clbkp;
	int ret = 1;

	if (first_call) {
		callback_list = getenv(ENV_CALLBACK_VAR);
		first_call = 0;
	}

	/* look in the ".callbacks" var for a reference to this variable */
	if (callback_list != NULL)
		ret = env_attr_lookup(callback_list, var_name, callback_name);

	/* only if not found there, look in the static list */
	if (ret)
		ret = env_attr_lookup(ENV_CALLBACK_LIST_STATIC, var_name,
			callback_name);

	/* if an association was found, set the callback pointer */
	if (!ret && strlen(callback_name)) {
		clbkp = find_env_callback(callback_name);
		if (clbkp != NULL)
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
			var_entry->callback = clbkp->callback + gd->reloc_off;
#else
			var_entry->callback = clbkp->callback;
#endif
	}
}
Пример #2
0
void 
env_set(struct lacy_env *env, char *ident, char *value)
{
    struct page_attr *e = env_attr_lookup(env, ident);
    if (NULL == e) {

        e = malloc(sizeof(struct page_attr));
        e->next = NULL;
        str_init(&(e->name));
        str_init(&(e->value));

        str_append_str(&(e->name), ident);
        str_append_str(&(e->value), value);

        if (env->sym_tbl == NULL) {
            env->sym_tbl = e;
        }
        else {
            struct page_attr *t = env->sym_tbl;
            while (t->next != NULL) 
                t = t->next;
            
            t->next = e;
        }
    }
    else {
        str_clear(&(e->value));
        str_append_str(&(e->value), value);
    }
}
Пример #3
0
/*
 * Look for flags in a provided list and failing that the static list
 */
static inline int env_flags_lookup(const char *flags_list, const char *name,
	char *flags)
{
	int ret = 1;

	if (!flags)
		/* bad parameter */
		return -1;

	/* try the env first */
	if (flags_list)
		ret = env_attr_lookup(flags_list, name, flags);

	if (ret != 0)
		/* if not found in the env, look in the static list */
		ret = env_attr_lookup(ENV_FLAGS_LIST_STATIC, name, flags);

	return ret;
}
Пример #4
0
/*
 * Look for a possible callback for a newly added variable
 * This is called specifically when the variable did not exist in the hash
 * previously, so the blanket update did not find this variable.
 */
void env_callback_init(ENTRY *var_entry)
{
	const char *var_name = var_entry->key;
	const char *callback_list = getenv(ENV_CALLBACK_VAR);
	char callback_name[256] = "";
	struct env_clbk_tbl *clbkp;
	int ret = 1;

	/* look in the ".callbacks" var for a reference to this variable */
	if (callback_list != NULL)
		ret = env_attr_lookup(callback_list, var_name, callback_name);

	/* only if not found there, look in the static list */
	if (ret)
		ret = env_attr_lookup(ENV_CALLBACK_LIST_STATIC, var_name,
			callback_name);

	/* if an association was found, set the callback pointer */
	if (!ret && strlen(callback_name)) {
		clbkp = find_env_callback(callback_name);
		if (clbkp != NULL)
			var_entry->callback = clbkp->callback;
	}
}
Пример #5
0
struct tree_node * 
write_var(FILE *out, struct tree_node *t, struct lacy_env *env)
{
    if (0 == strcmp(t->buffer.s, "root")) {
        write_depth(out, env);
    }
    else if (0 == strcmp(t->buffer.s, "this")) {
        struct page *p = env_get_page_top(env);
        if (NULL != p) {
            if (t->next != NULL && MEMBER == t->next->token) {
                t = t->next->next;
                t = write_member(out, t, p, env);
            }
            else {
                fprintf(out, "%s", p->file_path);
            }
        }
    }
    else {
        if (env_has_next(env)) {
            struct page_attr *a;
            a = env_attr_lookup(env, t->buffer.s);
            if (t->next != NULL && MEMBER == t->next->token) {
                t = t->next->next;
                if (NULL != a) {
                    struct page *p = page_find(a->value.s);
                    t = write_member(out, t, p, env);
                }
            }
            else 
            {
                if (NULL != a) {
                    fprintf(out, "%s", a->value.s);
                }
            }
        }
    }
    return t;
}
Пример #6
0
static int env_test_attrs_lookup_regex(struct unit_test_state *uts)
{
    char attrs[32];

    ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs));

    return 0;
}
Пример #7
0
static int env_test_attrs_lookup(struct unit_test_state *uts)
{
    char attrs[32];

    ut_assertok(env_attr_lookup("foo:bar", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup("foo : bar", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs));
    ut_asserteq_str("bar", attrs);

    ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs));

    ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs));

    ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs));
    ut_asserteq_str("baz", attrs);

    ut_assertok(env_attr_lookup(
                    " foo : bar , foo : bat , foot : baz ", "foo", attrs));
    ut_asserteq_str("bat", attrs);

    ut_assertok(env_attr_lookup(
                    " foo : bar , foo : bat , ufoo : baz ", "foo", attrs));
    ut_asserteq_str("bat", attrs);

    ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs));
    ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL));

    return 0;
}