1
#| environ.jl -- Functions to manipulate the process-environment
3
$Id: environ.jl,v 1.7 2000/08/13 19:14:52 john Exp $
5
Copyright (C) 1998 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of librep.
9
librep is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
librep is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with librep; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(declare (in-module rep.system))
26
(open-structures '(rep.regexp
31
"Return the value of the environment variable NAME, a string. The variable
32
`process-environment' is used to find the value."
33
(let ((regexp (concat (quote-regexp name) ?=)))
34
(let loop ((rest process-environment))
35
(cond ((null rest) nil)
36
((string-looking-at regexp (car rest))
37
(substring (car rest) (match-end)))
38
(t (loop (cdr rest)))))))
41
(defun setenv (name value)
42
"Set the current value of the environment variable NAME to the string VALUE.
43
The `process-environment' variable is destructively modified."
44
(let ((regexp (concat (quote-regexp name) ?=)))
45
(let loop ((rest process-environment))
47
(setq process-environment (cons (concat name #\= value)
48
process-environment)))
49
((string-looking-at regexp (car rest))
50
(rplaca rest (concat name #\= value)))
51
(t (loop (cdr rest)))))))
54
(defun unsetenv (name)
55
"Delete the environment variable called NAME."
56
(let ((re (concat (quote-regexp name) ?=)))
57
(setq process-environment
58
(delete-if (lambda (x)
59
(string-looking-at re x)) process-environment))))