Exemple #1
0
struct dag_variable_value *dag_variable_lookup(const char *name, struct dag_variable_lookup_set *s )
{
    struct dag_variable_value *v;

    if(!s)
        return NULL;

    /* Try node variables table */
    if(s->node) {
        v = dag_variable_get_value(name, s->node->variables, s->node->nodeid);
        if(v) {
            s->table = s->node->variables; //why this line?
            return v;
        }
    }

    if(!s->dag)
        return NULL;

    /* Try the category variables table */
    if(s->category) {
        v = dag_variable_get_value(name, s->category->mf_variables, s->dag->nodeid_counter);
        if(v) {
            s->table = s->dag->default_category->mf_variables;
            return v;
        }
    }

    /* Try dag variables table */
    v = dag_variable_get_value(name, s->dag->default_category->mf_variables, s->dag->nodeid_counter);
    if(v) {
        s->table = s->dag->default_category->mf_variables;
        return v;
    }

    /* Try the environment last. */
    char *value = getenv(name);
    if(value) {
        return dag_variable_value_create(value);
    }

    return NULL;
}
Exemple #2
0
void dag_close_over_environment(struct dag *d)
{
	//for each exported and special variable, if the variable does not have a
	//value assigned yet, we look for its value in the running environment

	char *name;
	struct dag_variable_value *v;

	set_first_element(d->special_vars);
	while((name = set_next_element(d->special_vars)))
	{
		v = dag_variable_get_value(name, d->variables, d->nodeid_counter);
		if(!v)
		{
			char *value_env = getenv(name);
			if(value_env)
			{
				dag_variable_add_value(name, d->variables, 0, value_env);
			}
		}
	}

	set_first_element(d->export_vars);
	while((name = set_next_element(d->export_vars)))
	{
		v = dag_variable_get_value(name, d->variables, d->nodeid_counter);
		if(!v)
		{
			char *value_env = getenv(name);
			if(value_env)
			{
				dag_variable_add_value(name, d->variables, 0, value_env);
			}
		}
	}

}
Exemple #3
0
void dag_parse_append_variable(struct lexer *bk, int nodeid, struct dag_node *n, const char *name, const char *value)
{
	struct dag_variable_lookup_set      sd = { bk->d, NULL, NULL, NULL };
	struct dag_variable_value *vd = dag_variable_lookup(name, &sd);

	struct dag_variable_value *v;
	if(n)
	{
		v = dag_variable_get_value(name, n->variables, nodeid);
		if(v)
		{
			dag_variable_value_append_or_create(v, value);
		}
		else
		{
			char *new_value;
			if(vd)
			{
				new_value = string_format("%s %s", vd->value, value);
			}
			else
			{
				new_value = xxstrdup(value);
			}
			dag_variable_add_value(name, n->variables, nodeid, new_value);
			free(new_value);
		}
	}
	else
	{
		if(vd)
		{
			dag_variable_value_append_or_create(vd, value);
		}
		else
		{
			dag_variable_add_value(name, bk->d->variables, nodeid, value);
		}
	}
}