searching for share directories, was: 5.11.0 can not load diff_form



Robert Dodier wrote:
> OK, here is an attempt at some Lisp code to look for share directories.
>
Here is an alternative.  The only advantage of this one is that it
doesn't operate on strings, but pathname objects, so it should be
independent of the actual filesystem.  The disadvantage is that gcl's
enough-namestring doesn't seem to be working as expected.

I've tested this with cmucl, clisp, and gcl.  gcl needs work to get just
the subdirectory name.

Sample usage is (find-share-directories <full path to share>).

Ray


(defun find-share-directories (base-pathname)
  (let ((wild-path (merge-pathnames #+gcl "**/"
                    #-gcl "**/*.*"
                    base-pathname)))
    (flet ((dirs-only (paths)
         ;; From the list of PATHS, extract out just the
         ;; directories.  We do this by filling a hashtable with
         ;; pathnames of the pathname-directories of each path.
         ;; This will give us unique directories.  (Could have
         ;; used pushnew too.)
         (let ((dir-hash (make-hash-table :test 'equal)))
           (dolist (p paths)
         (let ((d (pathname-directory p)))
           ;; Ignore CVS directories.
           (unless (equal (car (last d)) "CVS")
             (setf (gethash (make-pathname :directory d)
                    dir-hash)
               t))))
           (let (d)
         ;; Go through the hash table and convert the
         ;; directories to namestrings via enough-namestring.
         (maphash #'(lambda (k v)
                  (push (enough-namestring k base-pathname)
                    d))
              dir-hash)
         d))))
      ;; Find all files in the base-pathname directory and subdirectory.
      (dirs-only
       #+cmu (directory wild-path :truenamep nil :follow-links nil)
       #-cmu (directory wild-path)))))