mirror of
https://github.com/false-schemers/skint.git
synced 2024-11-16 07:47:54 +01:00
get-environment-variables
This commit is contained in:
parent
76dcf09bcc
commit
a7fb308858
3 changed files with 42 additions and 18 deletions
7
i.c
7
i.c
|
@ -3874,9 +3874,10 @@ define_instruction(fren) {
|
||||||
}
|
}
|
||||||
|
|
||||||
define_instruction(argvref) {
|
define_instruction(argvref) {
|
||||||
|
extern char *argv_ref(int idx);
|
||||||
int i; char *s; ckk(ac);
|
int i; char *s; ckk(ac);
|
||||||
i = get_fixnum(ac); /* todo: range-check */
|
i = get_fixnum(ac); /* todo: range-check */
|
||||||
s = cxg_argv[i];
|
s = argv_ref(i);
|
||||||
if (s) ac = string_obj(newstring(s));
|
if (s) ac = string_obj(newstring(s));
|
||||||
else ac = bool_obj(0);
|
else ac = bool_obj(0);
|
||||||
gonexti();
|
gonexti();
|
||||||
|
@ -3891,10 +3892,10 @@ define_instruction(getenv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
define_instruction(envvref) {
|
define_instruction(envvref) {
|
||||||
extern const char *environ_ref(int idx);
|
extern char *envv_ref(int idx);
|
||||||
int i; char *s; ckk(ac);
|
int i; char *s; ckk(ac);
|
||||||
i = get_fixnum(ac); /* todo: range-check */
|
i = get_fixnum(ac); /* todo: range-check */
|
||||||
s = (char *)environ_ref(i);
|
s = envv_ref(i);
|
||||||
if (s) ac = string_obj(newstring(s));
|
if (s) ac = string_obj(newstring(s));
|
||||||
else ac = bool_obj(0);
|
else ac = bool_obj(0);
|
||||||
gonexti();
|
gonexti();
|
||||||
|
|
38
s.c
38
s.c
|
@ -17,21 +17,30 @@ int dirsep = '\\';
|
||||||
int dirsep = '/';
|
int dirsep = '/';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32)
|
extern char *argv_ref(int idx)
|
||||||
#define sxc_environ _environ
|
|
||||||
#elif defined(__linux) || defined(__APPLE__)
|
|
||||||
#define sxc_environ environ
|
|
||||||
#else /* add more systems? */
|
|
||||||
char **sxc_environ = { NULL };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern const char *environ_ref(int idx)
|
|
||||||
{
|
{
|
||||||
const char **pe = sxc_environ;
|
char **pv = cxg_argv;
|
||||||
/* be careful with indexing! */
|
/* be careful with indexing! */
|
||||||
if (idx < 0) return NULL;
|
if (idx < 0) return NULL;
|
||||||
while (idx-- > 0) if (*pe++ == NULL) return NULL;
|
while (idx-- > 0) if (*pv++ == NULL) return NULL;
|
||||||
return *pe;
|
return *pv;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
#define cxg_envv _environ
|
||||||
|
#elif defined(__linux) || defined(__APPLE__)
|
||||||
|
#define cxg_envv environ
|
||||||
|
#else /* add more systems? */
|
||||||
|
char **cxg_envv = { NULL };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern char *envv_ref(int idx)
|
||||||
|
{
|
||||||
|
char **pv = cxg_envv;
|
||||||
|
/* be careful with indexing! */
|
||||||
|
if (idx < 0) return NULL;
|
||||||
|
while (idx-- > 0) if (*pv++ == NULL) return NULL;
|
||||||
|
return *pv;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *s_code[] = {
|
char *s_code[] = {
|
||||||
|
@ -1040,6 +1049,11 @@ char *s_code[] = {
|
||||||
"P", "feature-available?",
|
"P", "feature-available?",
|
||||||
"%1.0Y0?{${@(y8:features)[00},.1A0]1}f]1",
|
"%1.0Y0?{${@(y8:features)[00},.1A0]1}f]1",
|
||||||
|
|
||||||
|
"C", 0,
|
||||||
|
"f,#0.0,&1{%0:0^,.0?{.0]1}'0,n,,#0.0,:0,&2{%2.1Z2,.0?{.0,'(c=)S8,.0?{.0"
|
||||||
|
",'0,.3S7}{.1},.1?{.2S3,'1,.3I+,.4S7}{'(s0:)},'1,.6I+,.5,.2,.4cc,:1^[62"
|
||||||
|
"}.1A9:!0:0^]3}.!0.0^_1[12}_1@!(y25:get-environment-variables)",
|
||||||
|
|
||||||
"P", "emergency-exit",
|
"P", "emergency-exit",
|
||||||
"%!0.0u?{tZ9]1}.0aZ9]1",
|
"%!0.0u?{tZ9]1}.0aZ9]1",
|
||||||
|
|
||||||
|
|
15
src/s.scm
15
src/s.scm
|
@ -1955,9 +1955,18 @@
|
||||||
|
|
||||||
(define (feature-available? f) (and (symbol? f) (memq f (features))))
|
(define (feature-available? f) (and (symbol? f) (memq f (features))))
|
||||||
|
|
||||||
;TBD:
|
(define get-environment-variables
|
||||||
;
|
(let ([evl #f])
|
||||||
;get-environment-variables
|
(lambda ()
|
||||||
|
(or evl
|
||||||
|
(let loop ([r '()] [i 0])
|
||||||
|
(let ([kvs (%envv-ref i)])
|
||||||
|
(if kvs
|
||||||
|
(let* ([p (string-position #\= kvs)] ; should be there?
|
||||||
|
[key (if p (substring kvs 0 p) kvs)]
|
||||||
|
[val (if p (substring kvs (fx+ p 1) (string-length kvs)) "")])
|
||||||
|
(loop (cons (cons key val) r) (fx+ i 1)))
|
||||||
|
(begin (set! evl (reverse! r)) evl))))))))
|
||||||
|
|
||||||
(define (emergency-exit . ?obj)
|
(define (emergency-exit . ?obj)
|
||||||
(if (null? ?obj) (%exit) (%exit (car ?obj))))
|
(if (null? ?obj) (%exit) (%exit (car ?obj))))
|
||||||
|
|
Loading…
Reference in a new issue