~ubuntu-branches/ubuntu/trusty/librep/trusty

« back to all changes in this revision

Viewing changes to lisp/rep/system/environ.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2001-11-13 15:06:22 UTC
  • Revision ID: james.westby@ubuntu.com-20011113150622-vgmgmk6srj3kldr3
Tags: upstream-0.15.2
ImportĀ upstreamĀ versionĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#| environ.jl -- Functions to manipulate the process-environment
 
2
 
 
3
   $Id: environ.jl,v 1.7 2000/08/13 19:14:52 john Exp $
 
4
 
 
5
   Copyright (C) 1998 John Harper <john@dcs.warwick.ac.uk>
 
6
 
 
7
   This file is part of librep.
 
8
 
 
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)
 
12
   any later version.
 
13
 
 
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.
 
18
 
 
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.
 
22
|#
 
23
 
 
24
(declare (in-module rep.system))
 
25
 
 
26
(open-structures '(rep.regexp
 
27
                   rep.data))
 
28
 
 
29
;;;###autoload
 
30
(defun getenv (name)
 
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)))))))
 
39
 
 
40
;;;###autoload
 
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))
 
46
      (cond ((null rest)
 
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)))))))
 
52
 
 
53
;;;###autoload
 
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))))