Add delete-directory primitive.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Tue, 7 Jul 1992 00:44:54 +0000 (00:44 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Tue, 7 Jul 1992 00:44:54 +0000 (00:44 +0000)
Merge in DOS get-environment-variable/set-environment-variable!
changes.

v7/src/runtime/unxprm.scm

index c5857322987a10441ccd6186640a5ddfd989cc04..2751e64fd57fffcd8044d94e36fa5d00749a398f 100644 (file)
@@ -1,8 +1,8 @@
 #| -*-Scheme-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/unxprm.scm,v 1.18 1992/05/26 05:55:47 mhwu Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/unxprm.scm,v 1.19 1992/07/07 00:44:54 jinx Exp $
 
-Copyright (c) 1988-91 Massachusetts Institute of Technology
+Copyright (c) 1988-1992 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -71,7 +71,11 @@ MIT in each case. |#
 
 (define (call-with-temporary-filename receiver)
   (let find-eligible-directory
-      ((eligible-directories '("." "/tmp" "/usr/tmp")))
+      ((eligible-directories 
+       (let ((tmp (or (get-environment-variable "TEMP")
+                      (get-environment-variable "TMP")))
+             (others '("." "/tmp" "/usr/tmp")))
+         (if (not tmp) others (cons tmp others)))))
     (if (null? eligible-directories)
        (error "Can't locate directory for temporary file")
        (let ((dir (->namestring
@@ -94,7 +98,6 @@ MIT in each case. |#
                         (lambda () (if (file-exists? name)
                                        (delete-file name))))))))
              (find-eligible-directory (cdr eligible-directories)))))))
-    
 \f
 (define (file-attributes-direct filename)
   ((ucode-primitive file-attributes)
@@ -133,9 +136,50 @@ MIT in each case. |#
 (define file-modification-time
   file-modification-time-indirect)
 \f
-(define-integrable get-environment-variable
-  (ucode-primitive get-environment-variable))
-
+(define get-environment-variable)
+(define set-environment-variable!)
+(define delete-environment-variable!)
+(define reset-environment-variables!)
+
+(let ((environment-variables '()))
+  ;; Kludge: since getenv returns false for unbound,
+  ;; that can also be the marker for a deleted variable
+  (define-integrable *variable-deleted* false)
+
+  (set! get-environment-variable
+       (lambda (variable)
+         (cond ((not (string? variable))
+                (error "GET-ENVIRONMENT-VARIABLE: Variable must be a string"
+                       variable))
+               ((assoc variable environment-variables)
+                =>
+                cdr)
+               (else ((ucode-primitive get-environment-variable)
+                      variable)))))
+
+  (set! set-environment-variable!
+       (lambda (variable value)
+         (cond ((not (string? variable))
+                (error "SET-ENVIRONMENT-VARIABLE!: Variable must be a string"
+                       variable value))
+               ((assoc variable environment-variables)
+                =>
+                (lambda (pair)
+                  (set-cdr! pair value)))
+               (else
+                (set! environment-variables
+                      (cons (cons variable value)
+                            environment-variables))))
+         unspecific))
+
+  (set! delete-environment-variable!
+       (lambda (variable)
+         (set-environment-variable! variable *variable-deleted*)))
+
+  (set! reset-environment-variables!
+       (lambda () (set! environment-variables '())))
+) ; End LET
+\f
 (define (unix/user-home-directory user-name)
   (let ((directory ((ucode-primitive get-user-home-directory) user-name)))
     (if (not directory)
@@ -176,5 +220,14 @@ MIT in each case. |#
   ((ucode-primitive file-touch) (->namestring (merge-pathnames filename))))
 
 (define (make-directory name)
-  ((ucode-primitive directory-make)
-   (->namestring (pathname-as-directory (merge-pathnames name)))))
\ No newline at end of file
+  ((ucode-primitive directory-make 1)
+   (->namestring (pathname-as-directory (merge-pathnames name)))))
+
+(define (delete-directory name)
+  ((ucode-primitive directory-delete 1)
+   (->namestring (pathname-as-directory (merge-pathnames name)))))
+\f
+;;; Queues after-restart daemon to clean up environment space
+
+(define (initialize-system-primitives!)
+  (add-event-receiver! event:after-restart reset-environment-variables!))
\ No newline at end of file