static const char *env_get(struct env *env, const char *name) { const char *v; if (!env_find(env, name, NULL, &v)) return v; return NULL; }
PRIVATE int cmd_env(struct comal_line *line) { if (line->lc.id == NULL) cmd_env_list(); else curenv = env_find(line->lc.id->name); return 0; }
static void env_del(struct env *env, const char *name) { struct buffer *bu = &env->data; const char *n, *v; unsigned nlen, vlen; if (env_find(env, name, &n, &v)) return; nlen = strlen(n) + 1; vlen = strlen(v) + 1; /* cheat to turn a const into non-const */ memmove(bu->data + (n - bu->data), v + vlen, nlen + vlen); }
int env_find(env_t *env, char *name, proftalk_expr_t *result) { if (env == NULL) return 0; node_t *var = env->vars.head; while (var != NULL) { pair_t realvar = *(pair_t *)var->data; if (!strcmp(realvar.key, name)) { *result = realvar.val; return 1; } var = var->next; } return env_find(env->parent, name, result); }
NODE* env_find(ENV* env, const char* name) { int index; assert(env != NULL); assert(name != NULL && strcmp(name, "") != 0); index = env_getindex(env, name); if( index >= 0 ) { //printf("env_find: name=%s found address=%x\n", name, env->nodes[index]); NODE_CHECK(env->nodes[index]); return env->nodes[index]; } if( env->parent != NULL ) { return env_find(env->parent, name); } //printf("env_find: name=%s return NULL\n", name); return NULL; }