annotate lisp/find-paths.el @ 319:5164ebf671d9 r21-0-57

Added tag r21-0b57 for changeset afd57c14dfc8
author cvs
date Mon, 13 Aug 2007 10:45:37 +0200
parents 33bdb3d4b97f
children 182f72e8cd0d
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
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
39 (defvar paths-version-control-filename-regexp
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
40 "^\\(RCS\\|CVS\\|SCCS\\)$"
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
41 "File bases associated with version control.")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
42
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
43 (defvar paths-lisp-filename-regexp
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
44 "^\\(.*\\.elc?\\)$"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
45 "File bases that contain Lisp file.")
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
46
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
47 (defvar paths-no-lisp-directory-regexp
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
48 (concat "\\(" paths-version-control-filename-regexp "\\)"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
49 "\\|"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
50 "\\(" paths-lisp-filename-regexp "\\)")
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
51 "File bases that may not be directories containing Lisp code.")
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
52
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
53 (defun paths-find-recursive-path (directories &optional max-depth exclude-regexp)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
54 "Return a list of the directory hierarchy underneath DIRECTORIES.
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
55 The returned list is sorted by pre-order and lexicographically.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
56 MAX-DEPTH limits the depth of the search to MAX-DEPTH level,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
57 if it is a number. If MAX-DEPTH is NIL, the search depth is unlimited.
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
58 EXCLUDE-REGEXP is a regexp that matches directory names to exclude
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
59 from the search."
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
60 (let ((path '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
61 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
62 (let ((directory (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
63 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
64 (car directories)))))
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
65 (if (paths-file-readable-directory-p directory)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
66 (let ((raw-entries
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
67 (if (equal 0 max-depth)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
68 '()
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
69 (directory-files directory nil "^[^.-]")))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
70 (reverse-dirs '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
71
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
72 (while raw-entries
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
73 (if (null (string-match exclude-regexp (car raw-entries)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
74 (setq reverse-dirs
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
75 (cons (expand-file-name (car raw-entries) directory)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
76 reverse-dirs)))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
77 (setq raw-entries (cdr raw-entries)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
78
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
79 (let ((sub-path
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
80 (paths-find-recursive-path (reverse reverse-dirs)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
81 (if (numberp max-depth)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
82 (- max-depth 1)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
83 max-depth)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
84 exclude-regexp)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
85 (setq path (nconc path
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
86 (list directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
87 sub-path))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
88 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
89 path))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
90
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
91 (defun paths-file-readable-directory-p (filename)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
92 "Check if filename is a readable directory."
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
93 (and (file-directory-p filename)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
94 (file-readable-p filename)))
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
95
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
96 (defun paths-find-recursive-load-path (directories &optional max-depth)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
97 "Construct a recursive load path underneath DIRECTORIES."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
98 (paths-find-recursive-path directories
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
99 max-depth paths-no-lisp-directory-regexp))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
100
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
101 (defun paths-emacs-root-p (directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
102 "Check if DIRECTORY is a plausible installation root for XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
103 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
104 ;; installed
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
105 (paths-file-readable-directory-p (paths-construct-path (list directory
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
106 "lib"
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
107 emacs-program-name)))
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 286
diff changeset
108 ;; in-place or windows-nt
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
109 (and
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
110 (paths-file-readable-directory-p (paths-construct-path (list directory "lisp")))
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
111 (paths-file-readable-directory-p (paths-construct-path (list directory "etc"))))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
112
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
113 (defun paths-chase-symlink (file-name)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
114 "Chase a symlink until the bitter end."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
115 (let ((maybe-symlink (file-symlink-p file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
116 (if maybe-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
117 (let* ((directory (file-name-directory file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
118 (destination (expand-file-name maybe-symlink directory)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
119 (paths-chase-symlink destination))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
120 file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
121
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
122 (defun paths-find-emacs-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
123 (invocation-directory invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
124 "Find the run-time root of XEmacs."
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
125 (let* ((executable-file-name (paths-chase-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
126 (concat invocation-directory
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
127 invocation-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
128 (executable-directory (file-name-directory executable-file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
129 (maybe-root-1 (file-name-as-directory
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
130 (paths-construct-path '("..") executable-directory)))
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
131 (maybe-root-2 (file-name-as-directory
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
132 (paths-construct-path '(".." "..") executable-directory))))
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
133 (or (and (paths-emacs-root-p maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
134 maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
135 (and (paths-emacs-root-p maybe-root-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
136 maybe-root-2))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
137
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
138 (defun paths-construct-path (components &optional expand-directory)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
139 "Convert list of path components COMPONENTS into a path.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
140 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
141 to EXPAND-FILE-NAME."
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
142 (let* ((reverse-components (reverse components))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
143 (last-component (car reverse-components))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
144 (first-components (reverse (cdr reverse-components)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
145 (path
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
146 (apply #'concat
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
147 (append (mapcar #'file-name-as-directory first-components)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
148 (list last-component)))))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
149 (if expand-directory
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
150 (expand-file-name path expand-directory)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
151 path)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
152
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
153 (defun paths-construct-emacs-directory (root suffix base)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
154 "Construct a directory name within the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
155 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
156 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
157 (concat
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
158 (file-name-as-directory root)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
159 suffix
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
160 base))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
161
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
162 (defun paths-find-emacs-directory (roots suffix base
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
163 &optional envvar default keep-suffix)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
164 "Find a directory in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
165 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
166 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
167 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
168 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
169 specify the directory.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
170 DEFAULT is the preferred value.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
171 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
172 the directory."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
173 (let ((preferred-value (or (and envvar (getenv envvar))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
174 default)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
175 (if (and preferred-value
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
176 (paths-file-readable-directory-p preferred-value))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
177 (file-name-as-directory preferred-value)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
178 (catch 'gotcha
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
179 (while roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
180 (let* ((root (car roots))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
181 ;; installed
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
182 (path (paths-construct-emacs-directory root suffix base)))
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
183 (if (paths-file-readable-directory-p path)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
184 (throw 'gotcha path)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
185 ;; in-place
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
186 (if (null keep-suffix)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
187 (let ((path (paths-construct-emacs-directory root "" base)))
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
188 (if (paths-file-readable-directory-p path)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
189 (throw 'gotcha path))))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
190 (setq roots (cdr roots)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
191 nil))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
192
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
193 (defun paths-find-site-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
194 "Find a site-specific directory in the XEmacs hierarchy."
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
195 (paths-find-emacs-directory roots
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
196 (file-name-as-directory
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
197 (paths-construct-path (list
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
198 "lib"
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
199 emacs-program-name)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
200 base
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
201 envvar default))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
202
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
203 (defun paths-find-version-directory (roots base
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
204 &optional envvar default enforce-version)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
205 "Find a version-specific directory in the XEmacs hierarchy.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
206 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
207 (paths-find-emacs-directory roots
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
208 (file-name-as-directory
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
209 (paths-construct-path
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
210 (list "lib"
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
211 (construct-emacs-version-name))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
212 base
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
213 envvar default
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
214 enforce-version))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
215
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
216 (defun paths-find-architecture-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
217 "Find an architecture-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
218 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
219 ;; from more to less specific
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
220 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
221 (concat base system-configuration)
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
222 envvar)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
223 (paths-find-version-directory roots
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
224 base
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
225 envvar)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
226 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
227 system-configuration
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
228 envvar default)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
229
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
230 (defun construct-emacs-version-name ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
231 "Construct the raw XEmacs version number."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
232 (concat emacs-program-name "-" emacs-program-version))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
233
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
234 (defun paths-directories-which-exist (directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
235 "Return the directories among DIRECTORIES."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
236 (let ((reverse-directories '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
237 (while directories
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents: 298
diff changeset
238 (if (paths-file-readable-directory-p (car directories))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
239 (setq reverse-directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
240 (cons (car directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
241 reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
242 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
243 (reverse reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
244
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
245 (defun paths-uniq-append (list-1 list-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
246 "Append LIST-1 and LIST-2, omitting duplicates."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
247 (let ((reverse-survivors '()))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
248 (while list-2
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
249 (if (null (member (car list-2) list-1))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
250 (setq reverse-survivors (cons (car list-2) reverse-survivors)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
251 (setq list-2 (cdr list-2)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
252 (append list-1
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
253 (reverse reverse-survivors))))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
254
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
255 (defun paths-filter (predicate list)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
256 "Delete all matches of PREDICATE from LIST."
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
257 (let ((reverse-result '()))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
258 (while list
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
259 (if (funcall predicate (car list))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
260 (setq reverse-result (cons (car list) reverse-result)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
261 (setq list (cdr list)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
262 (nreverse reverse-result)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
263
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
264 (defun paths-decode-directory-path (string &optional drop-empties)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
265 "Split STRING at path separators into a directory list.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
266 Non-\"\" comonents are converted into directory form.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
267 If DROP-EMPTIES is non-NIL, \"\" components are dropped from the output.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
268 Otherwise, they are left alone."
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
269 (let* ((components (split-path string))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
270 (directories
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
271 (mapcar #'(lambda (component)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
272 (if (string-equal "" component)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
273 component
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
274 (file-name-as-directory component)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
275 components)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
276 (if drop-empties
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
277 (paths-filter #'(lambda (component)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
278 (null (string-equal "" component)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
279 directories)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
280 directories)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
281
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
282 (defun paths-find-emacs-roots (invocation-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
283 invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
284 "Find all plausible installation roots for XEmacs."
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
285 (let* ((potential-invocation-root
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
286 (paths-find-emacs-root invocation-directory invocation-name))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
287 (invocation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
288 (and potential-invocation-root
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
289 (list potential-invocation-root)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
290 (potential-installation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
291 (paths-uniq-append
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
292 (and configure-exec-prefix-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
293 (list (file-name-as-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
294 configure-exec-prefix-directory)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
295 (and configure-prefix-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
296 (list (file-name-as-directory
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
297 configure-prefix-directory)))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
298 (installation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
299 (paths-filter #'paths-emacs-root-p potential-installation-roots)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
300 (paths-uniq-append invocation-roots
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
301 installation-roots)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
302
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
303 ;;; find-paths.el ends here