Artifact
925ba1ca6faa311bc4d381c1f48c3f18bf6aaed0:
0000: 3b 3b 20 43 6f 70 79 72 69 67 68 74 20 28 63 29 ;; Copyright (c)
0010: 20 32 30 30 39 20 44 65 72 69 63 6b 20 45 64 64 2009 Derick Edd
0020: 69 6e 67 74 6f 6e 2e 20 20 41 6c 6c 20 72 69 67 ington. All rig
0030: 68 74 73 20 72 65 73 65 72 76 65 64 2e 0a 3b 3b hts reserved..;;
0040: 20 4c 69 63 65 6e 73 65 64 20 75 6e 64 65 72 20 Licensed under
0050: 61 6e 20 4d 49 54 2d 73 74 79 6c 65 20 6c 69 63 an MIT-style lic
0060: 65 6e 73 65 2e 20 20 4d 79 20 6c 69 63 65 6e 73 ense. My licens
0070: 65 20 69 73 20 69 6e 20 74 68 65 20 66 69 6c 65 e is in the file
0080: 0a 3b 3b 20 6e 61 6d 65 64 20 4c 49 43 45 4e 53 .;; named LICENS
0090: 45 20 66 72 6f 6d 20 74 68 65 20 6f 72 69 67 69 E from the origi
00a0: 6e 61 6c 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 74 nal collection t
00b0: 68 69 73 20 66 69 6c 65 20 69 73 20 64 69 73 74 his file is dist
00c0: 72 69 62 75 74 65 64 0a 3b 3b 20 77 69 74 68 2e ributed.;; with.
00d0: 20 20 49 66 20 74 68 69 73 20 66 69 6c 65 20 69 If this file i
00e0: 73 20 72 65 64 69 73 74 72 69 62 75 74 65 64 20 s redistributed
00f0: 77 69 74 68 20 73 6f 6d 65 20 6f 74 68 65 72 20 with some other
0100: 63 6f 6c 6c 65 63 74 69 6f 6e 2c 20 6d 79 0a 3b collection, my.;
0110: 3b 20 6c 69 63 65 6e 73 65 20 6d 75 73 74 20 61 ; license must a
0120: 6c 73 6f 20 62 65 20 69 6e 63 6c 75 64 65 64 2e lso be included.
0130: 0a 0a 3b 3b 20 49 6e 73 70 69 72 65 64 20 62 79 ..;; Inspired by
0140: 20 44 61 6e 6e 79 20 59 6f 6f 27 73 20 67 65 74 Danny Yoo's get
0150: 2d 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 50 4c 61 -environment PLa
0160: 6e 65 54 20 70 61 63 6b 61 67 65 2e 0a 0a 23 21 neT package...#!
0170: 72 36 72 73 0a 28 6c 69 62 72 61 72 79 20 28 73 r6rs.(library (s
0180: 72 66 69 20 73 39 38 20 6f 73 2d 65 6e 76 69 72 rfi s98 os-envir
0190: 6f 6e 6d 65 6e 74 2d 76 61 72 69 61 62 6c 65 73 onment-variables
01a0: 29 0a 20 20 28 65 78 70 6f 72 74 0a 20 20 20 20 ). (export.
01b0: 28 72 65 6e 61 6d 65 20 28 67 65 74 65 6e 76 20 (rename (getenv
01c0: 67 65 74 2d 65 6e 76 69 72 6f 6e 6d 65 6e 74 2d get-environment-
01d0: 76 61 72 69 61 62 6c 65 29 29 0a 20 20 20 20 67 variable)). g
01e0: 65 74 2d 65 6e 76 69 72 6f 6e 6d 65 6e 74 2d 76 et-environment-v
01f0: 61 72 69 61 62 6c 65 73 29 0a 20 20 28 69 6d 70 ariables). (imp
0200: 6f 72 74 0a 20 20 20 20 28 72 6e 72 73 20 62 61 ort. (rnrs ba
0210: 73 65 29 0a 20 20 20 20 28 6f 6e 6c 79 20 28 73 se). (only (s
0220: 63 68 65 6d 65 20 62 61 73 65 29 20 67 65 74 65 cheme base) gete
0230: 6e 76 29 0a 20 20 20 20 28 73 63 68 65 6d 65 20 nv). (scheme
0240: 66 6f 72 65 69 67 6e 29 29 0a 0a 20 20 28 75 6e foreign)).. (un
0250: 73 61 66 65 21 29 0a 0a 20 20 28 64 65 66 69 6e safe!).. (defin
0260: 65 20 65 6e 76 69 72 6f 6e 20 28 67 65 74 2d 66 e environ (get-f
0270: 66 69 2d 6f 62 6a 20 22 65 6e 76 69 72 6f 6e 22 fi-obj "environ"
0280: 20 28 66 66 69 2d 6c 69 62 20 23 46 29 20 5f 70 (ffi-lib #F) _p
0290: 6f 69 6e 74 65 72 29 29 0a 0a 20 20 28 64 65 66 ointer)).. (def
02a0: 69 6e 65 20 28 67 65 74 2d 65 6e 76 69 72 6f 6e ine (get-environ
02b0: 6d 65 6e 74 2d 76 61 72 69 61 62 6c 65 73 29 0a ment-variables).
02c0: 20 20 20 20 28 6c 65 74 20 6c 6f 6f 70 20 28 28 (let loop ((
02d0: 69 20 30 29 20 28 61 63 63 75 6d 20 27 28 29 29 i 0) (accum '())
02e0: 29 0a 20 20 20 20 20 20 28 6c 65 74 20 28 28 6e ). (let ((n
02f0: 65 78 74 20 28 70 74 72 2d 72 65 66 20 65 6e 76 ext (ptr-ref env
0300: 69 72 6f 6e 20 5f 73 74 72 69 6e 67 2f 6c 6f 63 iron _string/loc
0310: 61 6c 65 20 69 29 29 29 0a 20 20 20 20 20 20 20 ale i))).
0320: 20 28 69 66 20 6e 65 78 74 0a 20 20 20 20 20 20 (if next.
0330: 20 20 20 20 28 6c 6f 6f 70 20 28 2b 20 31 20 69 (loop (+ 1 i
0340: 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ).
0350: 20 20 28 63 6f 6e 73 20 28 6c 65 74 20 6c 6f 6f (cons (let loo
0360: 70 20 28 28 69 20 30 29 20 28 6c 65 6e 20 28 73 p ((i 0) (len (s
0370: 74 72 69 6e 67 2d 6c 65 6e 67 74 68 20 6e 65 78 tring-length nex
0380: 74 29 29 29 0a 20 20 20 20 20 20 20 20 20 20 20 t))).
0390: 20 20 20 20 20 20 20 20 20 20 20 20 20 28 69 66 (if
03a0: 20 28 3c 20 69 20 6c 65 6e 29 0a 20 20 20 20 20 (< i len).
03b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
03c0: 20 20 20 20 20 28 69 66 20 28 63 68 61 72 3d 3f (if (char=?
03d0: 20 23 5c 3d 20 28 73 74 72 69 6e 67 2d 72 65 66 #\= (string-ref
03e0: 20 6e 65 78 74 20 69 29 29 0a 20 20 20 20 20 20 next i)).
03f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0400: 20 20 20 20 20 20 28 63 6f 6e 73 20 28 73 75 62 (cons (sub
0410: 73 74 72 69 6e 67 20 6e 65 78 74 20 30 20 69 29 string next 0 i)
0420: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0430: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0440: 20 20 20 28 73 75 62 73 74 72 69 6e 67 20 6e 65 (substring ne
0450: 78 74 20 28 2b 20 31 20 69 29 20 6c 65 6e 29 29 xt (+ 1 i) len))
0460: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0470: 20 20 20 20 20 20 20 20 20 20 20 20 20 28 6c 6f (lo
0480: 6f 70 20 28 2b 20 31 20 69 29 20 6c 65 6e 29 29 op (+ 1 i) len))
0490: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
04a0: 20 20 20 20 20 20 20 20 20 20 20 28 63 6f 6e 73 (cons
04b0: 20 6e 65 78 74 20 23 46 29 29 29 0a 20 20 20 20 next #F))).
04c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
04d0: 20 20 61 63 63 75 6d 29 29 0a 20 20 20 20 20 20 accum)).
04e0: 20 20 20 20 61 63 63 75 6d 29 29 29 29 0a 29 0a accum)))).).