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 / ntdir.scm < prev    next >
Text File  |  1999-01-02  |  3KB  |  88 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: ntdir.scm,v 1.2 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1997, 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? full?)
  30.   (let ((sort? (if (default-object? sort?) #t sort?))
  31.     (full? (if (default-object? full?) #f full?)))
  32.     (let ((entries
  33.        (if full?
  34.            (directory-read-full pattern)
  35.            (directory-read-nosort pattern))))
  36.       (if (not sort?)
  37.       entries
  38.       (sort entries
  39.         (if full?
  40.             (lambda (x y) (pathname<? (car x) (car y)))
  41.             pathname<?))))))
  42.  
  43. (define (pathname<? x y)
  44.   (string-ci<? (file-namestring x) (file-namestring y)))
  45.  
  46. (define (directory-read-nosort pattern)
  47.   (let ((pattern (merge-pathnames pattern)))
  48.     (map (let ((directory-path (directory-pathname pattern)))
  49.        (lambda (pathname)
  50.          (merge-pathnames pathname directory-path)))
  51.      (let ((fnames (generate-directory-pathnames pattern)))
  52.        (fluid-let ((*expand-directory-prefixes?* #f))
  53.          (map ->pathname fnames))))))
  54.  
  55. (define (generate-directory-pathnames pathname)
  56.   (let ((channel (directory-channel-open (->namestring pathname))))
  57.     (let loop ((result '()))
  58.       (let ((name (directory-channel-read channel)))
  59.     (if name
  60.         (loop (cons name result))
  61.         (begin
  62.           (directory-channel-close channel)
  63.           result))))))
  64.  
  65. (define (directory-read-full pattern)
  66.   (let ((pattern (merge-pathnames pattern)))
  67.     (map (let ((directory-path (directory-pathname pattern)))
  68.        (lambda (entry)
  69.          (cons (merge-pathnames (car entry) directory-path)
  70.            (cdr entry))))
  71.      (let ((entries (generate-directory-entries pattern)))
  72.        (fluid-let ((*expand-directory-prefixes?* #f))
  73.          (map (lambda (entry) (cons (->pathname (car entry)) (cdr entry)))
  74.           entries))))))
  75.  
  76. (define (generate-directory-entries pathname)
  77.   (let ((channel (directory-channel-open (->namestring pathname))))
  78.     (let loop ((result '()))
  79.       (let ((entry (directory-channel-read-entry channel)))
  80.     (if entry
  81.         (loop (cons entry result))
  82.         (begin
  83.           (directory-channel-close channel)
  84.           result))))))
  85.  
  86. (define (directory-channel-read-entry channel)
  87.   ((ucode-primitive win32-directory-read 1)
  88.    (directory-channel/descriptor channel)))