annotate lisp/find-paths.el @ 284:558f606b08ae r21-0b40

Import from CVS: tag r21-0b40
author cvs
date Mon, 13 Aug 2007 10:34:13 +0200
parents 7df0dd720c89
children 57709be46d1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
1 ;;; find-paths.el --- setup various XEmacs paths
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
2
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
6
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
7 ;; Author: Mike Sperber <sperber@informatik.uni-tuebingen.de>
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
8 ;; Maintainer: XEmacs Development Team
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
9 ;; Keywords: internal, dumped
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
10
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
12
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
16 ;; any later version.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
17
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
21 ;; General Public License for more details.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
22
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
25 ;; Free Software Foundation, 59 Temple Place - Suite 330,
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
27
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
28 ;;; Synched up with: Not in FSF.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
29
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
30 ;;; Commentary:
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
31
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
32 ;; This file is dumped with XEmacs.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
33
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
34 ;; This file contains the library functionality to find paths into the
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
35 ;; XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
36
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
37 ;;; Code:
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
38
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
39 (defvar paths-version-control-bases '("RCS" "CVS" "SCCS")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
40 "File bases associated with version control.")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
41
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
42 (defun paths-find-recursive-path (directories &optional max-depth exclude)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
43 "Return a list of the directory hierarchy underneath DIRECTORIES.
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
44 The returned list is sorted by pre-order and lexicographically.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
45 MAX-DEPTH limits the depth of the search to MAX-DEPTH level,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
46 if it is a number. If MAX-DEPTH is NIL, the search depth is unlimited.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
47 EXCLUDE is a list of directory names to exclude from the search."
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
48 (let ((path '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
49 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
50 (let ((directory (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
51 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
52 (car directories)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
53 (if (file-directory-p directory)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
54 (let ((raw-dirs
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
55 (if (equal 0 max-depth)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
56 '()
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
57 (directory-files directory nil "^[^-.]" nil 'dirs-only)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
58 (reverse-dirs '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
59
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
60 (while raw-dirs
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
61 (if (null (member (car raw-dirs) exclude))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
62 (setq reverse-dirs
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
63 (cons (expand-file-name (car raw-dirs) directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
64 reverse-dirs)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
65 (setq raw-dirs (cdr raw-dirs)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
66
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
67 (let ((sub-path
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
68 (paths-find-recursive-path (reverse reverse-dirs)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
69 (if (numberp max-depth)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
70 (- max-depth 1)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
71 max-depth)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
72 exclude)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
73 (setq path (nconc path
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
74 (list directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
75 sub-path))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
76 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
77 path))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
78
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
79 (defun paths-find-recursive-load-path (directories &optional max-depth)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
80 "Construct a recursive load path underneath DIRECTORIES."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
81 (paths-find-recursive-path directories
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
82 max-depth paths-version-control-bases))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
83
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
84 (defun paths-emacs-root-p (directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
85 "Check if DIRECTORY is a plausible installation root for XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
86 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
87 ;; installed
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
88 (file-directory-p (paths-construct-path (list directory
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
89 "lib"
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
90 emacs-program-name)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
91 ;; in-place
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
92 (and
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
93 (file-directory-p (paths-construct-path (list directory "lib-src")))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
94 (file-directory-p (paths-construct-path (list directory "lisp")))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
95 (file-directory-p (paths-construct-path (list directory "src"))))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
96
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
97 (defun paths-chase-symlink (file-name)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
98 "Chase a symlink until the bitter end."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
99 (let ((maybe-symlink (file-symlink-p file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
100 (if maybe-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
101 (let* ((directory (file-name-directory file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
102 (destination (expand-file-name maybe-symlink directory)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
103 (paths-chase-symlink destination))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
104 file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
105
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
106 (defun paths-find-emacs-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
107 (invocation-directory invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
108 "Find the run-time root of XEmacs."
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
109 (let* ((executable-file-name (paths-chase-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
110 (concat invocation-directory
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
111 invocation-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
112 (executable-directory (file-name-directory executable-file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
113 (maybe-root-1 (file-name-as-directory
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
114 (paths-construct-path '("..") executable-directory)))
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
115 (maybe-root-2 (file-name-as-directory
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
116 (paths-construct-path '(".." "..") executable-directory))))
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
117 (or (and (paths-emacs-root-p maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
118 maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
119 (and (paths-emacs-root-p maybe-root-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
120 maybe-root-2))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
121
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
122 (defun paths-construct-path (components &optional expand-directory)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
123 "Convert list of path components COMPONENTS into a path.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
124 If EXPAND-DIRECTORY is non-NIL, use it as a directory to feed
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
125 to EXPAND-FILE-NAME."
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
126 (let* ((reverse-components (reverse components))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
127 (last-component (car reverse-components))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
128 (first-components (reverse (cdr reverse-components)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
129 (path
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
130 (apply #'concat
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
131 (append (mapcar #'file-name-as-directory first-components)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
132 (list last-component)))))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
133 (if expand-directory
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
134 (expand-file-name path expand-directory)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
135 path)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
136
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
137 (defun paths-construct-emacs-directory (root suffix base)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
138 "Construct a directory name within the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
139 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
140 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
141 (concat
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
142 (file-name-as-directory root)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
143 suffix
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
144 base))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
145
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
146 (defun paths-find-emacs-directory (roots suffix base
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
147 &optional envvar default keep-suffix)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
148 "Find a directory in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
149 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
150 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
151 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
152 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
153 specify the directory.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
154 DEFAULT is the preferred value.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
155 If KEEP-SUFFIX is non-nil, the suffix must be respected in searching
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
156 the directory."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
157 (let ((preferred-value (or (and envvar (getenv envvar))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
158 default)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
159 (if (and preferred-value
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
160 (file-directory-p preferred-value))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
161 (file-name-as-directory preferred-value)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
162 (catch 'gotcha
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
163 (while roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
164 (let* ((root (car roots))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
165 ;; installed
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
166 (path (paths-construct-emacs-directory root suffix base)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
167 (if (file-directory-p path)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
168 (throw 'gotcha path)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
169 ;; in-place
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
170 (if (null keep-suffix)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
171 (let ((path (paths-construct-emacs-directory root "" base)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
172 (if (file-directory-p path)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
173 (throw 'gotcha path))))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
174 (setq roots (cdr roots)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
175 nil))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
176
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
177 (defun paths-find-site-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
178 "Find a site-specific directory in the XEmacs hierarchy."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
179 (paths-find-emacs-directory roots
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
180 (file-name-as-directory
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
181 (paths-construct-path (list
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
182 "lib"
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
183 emacs-program-name)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
184 base
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
185 envvar default))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
186
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
187 (defun paths-find-version-directory (roots base
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
188 &optional envvar default enforce-version)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
189 "Find a version-specific directory in the XEmacs hierarchy.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
190 If ENFORCE-VERSION is non-nil, the directory must contain the XEmacs version."
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
191 (paths-find-emacs-directory roots
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
192 (file-name-as-directory
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
193 (paths-construct-path
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
194 (list "lib"
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
195 (construct-emacs-version-name))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
196 base
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
197 envvar default
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
198 enforce-version))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
199
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
200 (defun paths-find-architecture-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
201 "Find an architecture-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
202 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
203 ;; from more to less specific
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
204 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
205 (concat base system-configuration)
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
206 envvar)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
207 (paths-find-version-directory roots
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
208 base
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
209 envvar)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
210 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
211 system-configuration
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
212 envvar default)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
213
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
214 (defun construct-emacs-version-name ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
215 "Construct the raw XEmacs version number."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
216 (concat emacs-program-name "-" emacs-program-version))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
217
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
218 (defun paths-directories-which-exist (directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
219 "Return the directories among DIRECTORIES."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
220 (let ((reverse-directories '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
221 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
222 (if (file-directory-p (car directories))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
223 (setq reverse-directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
224 (cons (car directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
225 reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
226 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
227 (reverse reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
228
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
229 (defun paths-uniq-append (list-1 list-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
230 "Append LIST-1 and LIST-2, omitting duplicates."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
231 (let ((reverse-survivors '()))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
232 (while list-2
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
233 (if (null (member (car list-2) list-1))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
234 (setq reverse-survivors (cons (car list-2) reverse-survivors)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
235 (setq list-2 (cdr list-2)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
236 (append list-1
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
237 (reverse reverse-survivors))))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
238
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
239 (defun paths-filter (predicate list)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
240 "Delete all matches of PREDICATE from LIST."
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
241 (let ((reverse-result '()))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
242 (while list
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
243 (if (funcall predicate (car list))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
244 (setq reverse-result (cons (car list) reverse-result)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
245 (setq list (cdr list)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
246 (nreverse reverse-result)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
247
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
248 (defun paths-decode-directory-path (string &optional drop-empties)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
249 "Split STRING at path separators into a directory list.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
250 Non-\"\" comonents are converted into directory form.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
251 If DROP-EMPTIES is non-NIL, \"\" components are dropped from the output.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
252 Otherwise, they are left alone."
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
253 (let* ((components (split-path string))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
254 (directories
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
255 (mapcar #'(lambda (component)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
256 (if (string-equal "" component)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
257 component
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
258 (file-name-as-directory component)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
259 components)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
260 (if drop-empties
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
261 (paths-filter #'(lambda (component)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
262 (null (string-equal "" component)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
263 directories)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
264 directories)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
265
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
266 (defun paths-find-emacs-roots (invocation-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
267 invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
268 "Find all plausible installation roots for XEmacs."
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
269 (let* ((potential-invocation-root
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
270 (paths-find-emacs-root invocation-directory invocation-name))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
271 (invocation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
272 (and potential-invocation-root
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
273 (list potential-invocation-root)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
274 (potential-installation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
275 (paths-uniq-append
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
276 (and configure-exec-prefix-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
277 (list (file-name-as-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
278 configure-exec-prefix-directory)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
279 (and configure-prefix-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
280 (list (file-name-as-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
281 configure-prefix-directory)))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
282 (installation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
283 (paths-filter #'paths-emacs-root-p potential-installation-roots)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
284 (paths-uniq-append invocation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
285 installation-roots)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
286
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
287 ;;; find-paths.el ends here