annotate lisp/find-paths.el @ 380:8626e4521993 r21-2-5

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