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 / os2dir.scm < prev    next >
Text File  |  1999-01-02  |  2KB  |  54 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: os2dir.scm,v 1.5 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1994-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. ;;;; Directory Operations -- OS/2
  23. ;;; package: (runtime directory)
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define *expand-directory-prefixes?* #t)
  28.  
  29. (define (directory-read pattern #!optional sort?)
  30.   (if (if (default-object? sort?) #t sort?)
  31.       (sort (directory-read-nosort pattern) pathname<?)
  32.       (directory-read-nosort pattern)))
  33.  
  34. (define (directory-read-nosort pattern)
  35.   (let ((pattern (merge-pathnames pattern)))
  36.     (map (let ((directory-path (directory-pathname pattern)))
  37.        (lambda (pathname)
  38.          (merge-pathnames pathname directory-path)))
  39.      (let ((fnames (generate-directory-pathnames pattern)))
  40.        (fluid-let ((*expand-directory-prefixes?* #f))
  41.          (map ->pathname fnames))))))
  42.  
  43. (define (generate-directory-pathnames pathname)
  44.   (let ((channel (directory-channel-open (->namestring pathname))))
  45.     (let loop ((result '()))
  46.       (let ((name (directory-channel-read channel)))
  47.     (if name
  48.         (loop (cons name result))
  49.         (begin
  50.           (directory-channel-close channel)
  51.           result))))))
  52.  
  53. (define (pathname<? x y)
  54.   (string-ci<? (file-namestring x) (file-namestring y)))