From: Martin Ginkel
Subject: Compatible Logical Pathname translations?
Date: 
Message-ID: <cgf75f$2p26$1@gwdu112.gwdg.de>
Dear all,

I am currently struggling with logical pathnames of my program.

My goal: define logical pathnames for (a big bunch of) source and binary 
files in a config-file loaded prior compile and at image-start.
This should be the only place for putting physical paths.
Since this config is loaded at the very beginning, I can't write
lots of compatibility wrapping around it.

Approaches:
1. translation-tables as ACL hosts.cl are incompatible
2. (setf (logical-pathname-translations "host")) seems to be ok but:

("uffi:**;*.*.*" "/blu/uffi/**/*.*")

is not able to translate "uffi:uffi-config.lisp" on Clisp.
on allegro it is still working.
3.
For this i tried to add another rule:
("uffi:*.*.*" "/bla/blu/uffi/*.*")
("uffi:**;*.*.*" "/bla/blu/uffi/**/*.*")

But apparently the first pathspec "uffi:*.*.*" translates to
#s(logical-pathname ... :directory (:relative) ...)
In my opinion the dir is (:absolute ) or nil but for relative it must be
defined as "uffi:;*.*.*".

Anyways: since this relative paths seem to be the only compatible way, I 
left it that way.

Has anyone other experiences with logical paths?

	Thanks
	Martin



-- 
+-[Martin Ginkel]-------------[mailto:mginkel(at)mpi-magdeburg.mpg.de]-+
| MPI Magdeburg, Zi S2.09    Sandtorstr. 1, D-39106 Magdeburg, Germany |
| Confucious say: fool man climb tree to get cherries; wise man spread |
| limbs.                                                               |
+-[tel/fax: +49 391 6110 482/529]----[http://www.mpi-magdeburg.mpg.de]-+
From: Pascal Bourguignon
Subject: Re: Compatible Logical Pathname translations?
Date: 
Message-ID: <874qmszsmm.fsf@thalassa.informatimago.com>
Martin Ginkel <·············@epost.de> writes:

> Dear all,
> 
> I am currently struggling with logical pathnames of my program.
> 
> My goal: define logical pathnames for (a big bunch of) source and
> binary files in a config-file loaded prior compile and at image-start.
> This should be the only place for putting physical paths.
> Since this config is loaded at the very beginning, I can't write
> lots of compatibility wrapping around it.
> 
> Approaches:
> 1. translation-tables as ACL hosts.cl are incompatible
> 2. (setf (logical-pathname-translations "host")) seems to be ok but:
> 
> ("uffi:**;*.*.*" "/blu/uffi/**/*.*")
> 
> is not able to translate "uffi:uffi-config.lisp" on Clisp.
> on allegro it is still working.
> 3.
> For this i tried to add another rule:
> ("uffi:*.*.*" "/bla/blu/uffi/*.*")
> ("uffi:**;*.*.*" "/bla/blu/uffi/**/*.*")
> 
> But apparently the first pathspec "uffi:*.*.*" translates to
> #s(logical-pathname ... :directory (:relative) ...)
> In my opinion the dir is (:absolute ) or nil but for relative it must be
> defined as "uffi:;*.*.*".
> 
> Anyways: since this relative paths seem to be the only compatible way,
> I left it that way.
> 
> Has anyone other experiences with logical paths?

I use it like this (with cmucl, sbcl, clisp, openmcl):


(DEFMACRO DEF-LP-TRANS (HOST PATH &OPTIONAL SUBPATH)
  (SETQ SUBPATH (OR SUBPATH ""))
  `(LET ((DIRECTORY (APPEND (PATHNAME-DIRECTORY ,PATH)
                            (CDR (PATHNAME-DIRECTORY ,SUBPATH))
                            '( :WILD-INFERIORS ))))
     (SETF (LOGICAL-PATHNAME-TRANSLATIONS ,HOST)
           (LIST
            (LIST "**;*"     (MAKE-PATHNAME :DIRECTORY DIRECTORY
                                            :NAME :WILD))
            (LIST "**;*.*"   (MAKE-PATHNAME :DIRECTORY DIRECTORY
                                            :NAME :WILD :TYPE :WILD))
            (LIST "**;*.*.*" (MAKE-PATHNAME :DIRECTORY DIRECTORY
                                            :NAME :WILD :TYPE :WILD
                                            :VERSION :WILD)) )))
  );;DEF-LP-TRANS


(DEFCONSTANT +SHARE-LISP+ "/usr/local/share/lisp/")
(DEF-LP-TRANS "SHARE-LISP" +SHARE-LISP+)

(DEF-LP-TRANS "CMU-AI"     +SHARE-LISP+ "ai/")
(DEF-LP-TRANS "CL-PDF"     +SHARE-LISP+ "cl-pdf/")
(DEF-LP-TRANS "PSEUDO"     +SHARE-LISP+ "pseudo/")
(DEF-LP-TRANS "CLOCC"      +SHARE-LISP+ "packages/net/sourceforge/clocc/clocc/")



In addition I've got a PACKAGE package (exporting DEFINE-PACKAGE,
LOAD-PACKAGE and ADD-TRANSLATIONS) that allows me to load a package by
its name:
(load-package "COM.INFORMATIMAGO.COMMON-LISP.STRING") would load the file:
      "PACKAGE:COM;INFORMATIMAGO;COMMON-LISP;STRING" (and all dependencies).


(DEFUN ADD-TRANSLATIONS (&REST TRANSLATIONS)
  "
DO:         Prepend the TRANSLATIONS to the list of logical pathname
            translations of the PACKAGES: logical host.
            These translations may concern either the long names of package:
               the package COM.INFORMATIMAGO.COMMON-LIST.UTILITY
               is loaded from PACKAGES:COM;INFORMATIMAGO;COMMON-LISP;LIST
               which could be translated to:
               /usr/share/lisp/packages/com/informatimago/common-lisp/list.lisp
            or abstract, short nicknames:
               the package nicknamed DICTIONARY
               would be loaded from PACKAGES:DICTIONARY
               which could be translated to:
                       PACKAGES:COM;INFORMATIMAGO;COMMON-LISP;HASH-DICT
               or to:  PACKAGES:COM;INFORMATIMAGO;COMMON-LISP;BIN-TREE-DICT
"
  (SETF (LOGICAL-PATHNAME-TRANSLATIONS "PACKAGES")
        (NCONC (COPY-SEQ TRANSLATIONS)
               (HANDLER-CASE
                   (LOGICAL-PATHNAME-TRANSLATIONS "PACKAGES")
                 (ERROR NIL))))
  );;ADD-TRANSLATIONS


(DEFMACRO MP (PATHNAME &OPTIONAL
                       (DIRECTORY NIL DIRECTORY-P)
                       (NAME      NIL NAME-P)
                       (TYPE      NIL TYPE-P)
                       (VERSION   NIL VERSION-P))
  `(MERGE-PATHNAMES
    (MAKE-PATHNAME ,@(WHEN DIRECTORY-P `(:DIRECTORY '(:RELATIVE ,@DIRECTORY)))
                   ,@(WHEN NAME-P      `(:NAME      ,NAME))
                   ,@(WHEN TYPE-P      `(:TYPE      ,TYPE))
                   ,@(WHEN VERSION-P   `(:TYPE      ,VERSION)))
    ,PATHNAME));;MP


(PACKAGE:ADD-TRANSLATIONS
 (LIST "**;*"     (MP +SHARE-LISP+ ("packages" :WILD-INFERIORS) :WILD))
 (LIST "**;*.*"   (MP +SHARE-LISP+ ("packages" :WILD-INFERIORS) :WILD :WILD))
 (LIST "**;*.*.*" (MP +SHARE-LISP+ ("packages" :WILD-INFERIORS) :WILD :WILD :WILD)))



For SBCL, I noticed that it works better when the translations are
ordered in the other order:

#+sbcl (defun pstring (x) (if (pathnamep x) (namestring x) (string x)))
#+sbcl (setf (logical-pathname-translations "PACKAGES")
         (sort (copy-seq (logical-pathname-translations "PACKAGES"))
            (lambda (a b) (> (length (pstring (second a)))
                        (length (pstring (second b)))))))

(this should probably be done on the other logical hosts too).


It seems to me that ** (:wild-inferiors) include the base directory
too, so you don't need to include both "uffi:*.*.*" and "uffi:**;*.*.*".



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.