summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-05 19:59:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2011-11-05 19:59:05 -0700
commita5f2b7e6641a5f7ebaf01dd0e9fa10200ceb4606 (patch)
tree4e9c4f5083bd2b4016edf2555f3b2bcc032950ea /lib.c
parentb347ef4f083443e608b46f308894acc2567ce630 (diff)
downloadtxr-a5f2b7e6641a5f7ebaf01dd0e9fa10200ceb4606.tar.gz
txr-a5f2b7e6641a5f7ebaf01dd0e9fa10200ceb4606.tar.bz2
txr-a5f2b7e6641a5f7ebaf01dd0e9fa10200ceb4606.zip
Task #11442. Access to environment variables.
* lib.c (env_list): New static variable. (env): New function. (match): Declaration of nonexistent function removed. (obj_init): New variable gc-protected. * lib.h (env): Declared. * match.c (env_k): New symbol variable. (v_next): Implemented :env. * txr.1: @(next :env) described.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 6af8dd58..d874e3ab 100644
--- a/lib.c
+++ b/lib.c
@@ -76,6 +76,8 @@ val identity_f, equal_f, eq_f, car_f;
val prog_string;
+static val env_list;
+
mem_t *(*oom_realloc)(mem_t *, size_t);
val identity(val obj)
@@ -2297,6 +2299,23 @@ val set_diff(val list1, val list2, val testfun, val keyfun)
return out;
}
+val env(void)
+{
+ extern char **environ;
+ char **iter;
+
+ if (env_list) {
+ return env_list;
+ } else {
+ list_collect_decl (out, ptail);
+
+ for (iter = environ; *iter != 0; iter++)
+ list_collect (ptail, string_utf8(*iter));
+
+ return env_list = out;
+ }
+}
+
static void obj_init(void)
{
/*
@@ -2308,7 +2327,7 @@ static void obj_init(void)
protect(&packages, &system_package, &keyword_package,
&user_package, &null_string, &nil_string,
&null_list, &equal_f, &eq_f, &car_f,
- &identity_f, &prog_string,
+ &identity_f, &prog_string, &env_list,
(val *) 0);
nil_string = lit("nil");