> Looks good to me, please go ahead.
Find attached a patch that includes the implementation previously
attached, plus unit tests and additions to the NEWS and modules.texi
files.
Regards,
Julian
From a1e4bcb30b80199de6f2cd620d950d04e0734592 Mon Sep 17 00:00:00 2001
From: Julian Graham <jul...@transmetropolitan.(none)>
Date: Thu, 28 May 2009 18:15:05 -0400
Subject: [PATCH] Implementation of SRFI-98 (An interface to environment variables)
---
NEWS | 1 +
doc/ref/srfi-modules.texi | 19 +++++++++++++++++
module/srfi/srfi-98.scm | 44 +++++++++++++++++++++++++++++++++++++++++
test-suite/tests/srfi-98.test | 38 +++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 0 deletions(-)
create mode 100644 module/srfi/srfi-98.scm
create mode 100644 test-suite/tests/srfi-98.test
diff --git a/NEWS b/NEWS
index 1785fe8..94d6be7 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Changes in 1.9.0:
* New modules (see the manual for details)
** `(srfi srfi-18)', multithreading support
+** `(srfi srfi-98)', an interface to environment variables
** The `(ice-9 i18n)' module provides internationalization support
* Changes to the distribution
diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 1fa50b2..638aa46 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -47,6 +47,7 @@ get the relevant SRFI documents from the SRFI home page
* SRFI-61:: A more general `cond' clause
* SRFI-69:: Basic hash tables.
* SRFI-88:: Keyword objects.
+* SRFI-98:: An interface to access environment variables.
@end menu
@@ -3608,6 +3609,24 @@ Return the keyword object whose name is @var{str}.
@end example
@end deffn
+...@node SRFI-98
+...@subsection SRFI-98 An interface to access environment variables.
+...@cindex SRFI-98
+...@cindex environment variables
+
+This is a portable wrapper around Guile's built-in support for
+interacting with the current environment, @xref{Runtime Environment}.
+
+...@deffn {Scheme Procedure} get-environment-variable name
+Returns the value of the named environment variable as a string, or
+...@code{#f} if the named environment variable is not found. This is
+equivalent to @code{(getenv name)}.
+...@end deffn
+
+...@deffn {Scheme Procedure} get-environment-variables
+Returns names and values of all the environment variables as an
+association list.
+...@end deffn
@c srfi-modules.texi ends here
diff --git a/module/srfi/srfi-98.scm b/module/srfi/srfi-98.scm
new file mode 100644
index 0000000..924a205
--- /dev/null
+++ b/module/srfi/srfi-98.scm
@@ -0,0 +1,44 @@
+;;; srfi-98.scm --- An interface to access environment variables
+
+;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 2.1 of the License, or (at your option) any later version.
+;;
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Lesser General Public License for more details.
+;;
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+;;; Author: Julian Graham <[email protected]>
+;;; Date: 2009-05-26
+
+;;; Commentary:
+
+;; This is an implementation of SRFI-98 (An interface to access environment
+;; variables).
+;;
+;; This module is fully documented in the Guile Reference Manual.
+
+;;; Code:
+
+(define-module (srfi srfi-98)
+ :use-module (srfi srfi-1)
+ :export (get-environment-variable
+ get-environment-variables))
+
+(cond-expand-provide (current-module) '(srfi-98))
+
+(define get-environment-variable getenv)
+(define (get-environment-variables)
+ (define (string->alist-entry str)
+ (let ((pvt (string-index str #\=))
+ (len (string-length str)))
+ (and pvt (cons (substring str 0 pvt) (substring str (+ pvt 1) len)))))
+ (filter-map string->alist-entry (environ)))
diff --git a/test-suite/tests/srfi-98.test b/test-suite/tests/srfi-98.test
new file mode 100644
index 0000000..3fbb1ef
--- /dev/null
+++ b/test-suite/tests/srfi-98.test
@@ -0,0 +1,38 @@
+;;;; srfi-98.test --- Test suite for Guile's SRFI-98 functions. -*- scheme -*-
+;;;;
+;;;; Copyright 2009 Free Software Foundation, Inc.
+;;;;
+;;;; This program is free software; you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License as published by
+;;;; the Free Software Foundation; either version 2, or (at your option)
+;;;; any later version.
+;;;;
+;;;; This program is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;;; GNU General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with this software; see the file COPYING. If not, write to
+;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;;;; Boston, MA 02110-1301 USA
+
+(define-module (test-srfi-98)
+ #:use-module (srfi srfi-98)
+ #:use-module (test-suite lib))
+
+(with-test-prefix "get-environment-variable"
+ (pass-if "get-environment-variable retrieves binding"
+ (putenv "foo=bar")
+ (equal? (get-environment-variable "foo") "bar"))
+
+ (pass-if "get-environment-variable #f on unbound name"
+ (unsetenv "foo")
+ (not (get-environment-variable "foo"))))
+
+(with-test-prefix "get-environment-variables"
+
+ (pass-if "get-environment-variables contains binding"
+ (putenv "foo=bar")
+ (equal? (assoc-ref (get-environment-variables) "foo") "bar")))
+
--
1.6.0.4