home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / wrkdir.scm < prev    next >
Text File  |  1999-01-02  |  2KB  |  68 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: wrkdir.scm,v 14.8 1999/01/02 06:19:10 cph Exp $
  4.  
  5. Copyright (c) 1988-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Working Directory
  23. ;;; package: (runtime working-directory)
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define (initialize-package!)
  28.   (reset!)
  29.   (add-event-receiver! event:after-restore reset!))
  30.  
  31. (define (reset!)
  32.   (let ((pathname
  33.      (pathname-simplify
  34.       (pathname-as-directory
  35.        ((ucode-primitive working-directory-pathname))))))
  36.     (set! *working-directory-pathname* pathname)
  37.     (set! *default-pathname-defaults* pathname))
  38.   unspecific)
  39.  
  40. (define *working-directory-pathname*)
  41.  
  42. (define (working-directory-pathname)
  43.   *working-directory-pathname*)
  44.  
  45. (define (set-working-directory-pathname! name)
  46.   (let ((pathname
  47.      (pathname-as-directory
  48.       (merge-pathnames name *working-directory-pathname*))))
  49.     (if (not (file-directory? pathname))
  50.     (error "Not a valid directory:" pathname))
  51.     (let ((pathname (pathname-simplify pathname)))
  52.       (set! *working-directory-pathname* pathname)
  53.       (set! *default-pathname-defaults*
  54.         (merge-pathnames pathname *default-pathname-defaults*))
  55.       (cmdl/set-default-directory (nearest-cmdl) pathname)
  56.       pathname)))
  57.  
  58. (define (with-working-directory-pathname name thunk)
  59.   (let ((pathname
  60.      (pathname-as-directory
  61.       (merge-pathnames name *working-directory-pathname*))))
  62.     (if (not (file-directory? pathname))
  63.     (error "Not a valid directory:" pathname))
  64.     (let ((pathname (pathname-simplify pathname)))
  65.       (fluid-let ((*working-directory-pathname* pathname)
  66.           (*default-pathname-defaults*
  67.            (merge-pathnames pathname *default-pathname-defaults*)))
  68.     (thunk)))))