annotate lisp/find-paths.el @ 267:966663fcf606 r20-5b32

Import from CVS: tag r20-5b32
author cvs
date Mon, 13 Aug 2007 10:26:29 +0200
parents
children b2472a1930f2
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
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
42 (defun paths-find-recursive-path (directories &optional exclude)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
43 "Return a list of the directory hierarchy underneath DIRECTORIES.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
44 The returned list is sorted by pre-order and lexicographically."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
45 (let ((path '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
46 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
47 (let ((directory (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
48 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
49 (car directories)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
50 (if (file-directory-p directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
51 (let ((raw-dirs (directory-files directory nil "^[^-.]" nil 'dirs-only))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
52 (reverse-dirs '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
53
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
54 (while raw-dirs
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
55 (if (null (member (car raw-dirs) exclude))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
56 (setq reverse-dirs
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
57 (cons (expand-file-name (car raw-dirs) directory)
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 (setq raw-dirs (cdr raw-dirs)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
60
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
61 (let ((sub-path
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
62 (paths-find-recursive-path (reverse reverse-dirs) exclude)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
63 (setq path (nconc path
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
64 (list directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
65 sub-path))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
66 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
67 path))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
68
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
69 (defun paths-find-recursive-load-path (directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
70 "Construct a recursive load path underneath DIRECTORIES."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
71 (paths-find-recursive-path directories paths-version-control-bases))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
72
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
73 (defun paths-emacs-root-p (directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
74 "Check if DIRECTORY is a plausible installation root for XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
75 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
76 ;; installed
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
77 (file-directory-p
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
78 (concat directory "lib/xemacs-" (construct-emacs-version)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
79 ;; in-place
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
80 (and
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
81 (file-directory-p (concat directory "lib-src"))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
82 (file-directory-p (concat directory "lisp"))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
83 (file-directory-p (concat directory "src")))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
84
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
85 (defun paths-find-emacs-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
86 (invocation-directory invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
87 "Find the run-time root of XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
88 (let ((maybe-root-1 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
89 (expand-file-name ".." invocation-directory)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
90 (maybe-root-2 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
91 (expand-file-name "../.." invocation-directory))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
92 (cond
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
93 ((paths-emacs-root-p maybe-root-1)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
94 maybe-root-1)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
95 ((paths-emacs-root-p maybe-root-2)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
96 maybe-root-2)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
97 (t
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
98 (let ((maybe-symlink (file-symlink-p (concat invocation-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
99 invocation-name))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
100 (if maybe-symlink
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
101 (let ((directory (file-name-directory maybe-symlink)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
102 (paths-find-emacs-root directory invocation-name))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
103 nil))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
104
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
105 (defun paths-construct-emacs-directory (root suffix base)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
106 "Construct a directory name within the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
107 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
108 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
109 (concat
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
110 (file-name-as-directory root)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
111 suffix
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
112 base))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
113
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
114 (defun paths-find-emacs-directory (roots suffix base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
115 "Find a directory in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
116 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
117 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
118 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
119 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
120 specify the directory.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
121 DEFAULT is a fall-back value."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
122 (let ((envvar-value (and envvar (getenv envvar))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
123 (if (and envvar-value
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
124 (file-directory-p envvar-value))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
125 (file-name-as-directory envvar-value)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
126 (catch 'gotcha
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
127 (while roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
128 (let* ((root (car roots))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
129 (path (paths-construct-emacs-directory root suffix base)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
130 ;; installed
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
131 (if (file-directory-p path)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
132 (throw 'gotcha path)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
133 (let ((path (paths-construct-emacs-directory root "" base)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
134 ;; in-place
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
135 (if (file-directory-p path)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
136 (throw 'gotcha path)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
137 (setq roots (cdr roots)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
138 (if (and default
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
139 (file-directory-p default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
140 (file-name-as-directory default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
141 nil)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
142
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
143 (defun paths-find-site-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
144 "Find a site-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
145 (paths-find-emacs-directory roots "lib/xemacs/" base envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
146
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
147 (defun paths-find-version-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
148 "Find a version-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
149 (paths-find-emacs-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
150 (concat "lib/xemacs-" (construct-emacs-version) "/")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
151 base
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
152 envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
153
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
154 (defun paths-find-architecture-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
155 "Find an architecture-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
156 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
157 ;; from more to less specific
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
158 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
159 (concat base system-configuration)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
160 envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
161 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
162 system-configuration
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
163 envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
164 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
165 base
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
166 envvar default)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
167
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
168 (defvar paths-path-emacs-version nil
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
169 "Emacs version as it appears in paths.")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
170
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
171 (defun construct-emacs-version ()
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
172 "Construct the raw version number of XEmacs in the form XX.XX."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
173 ;; emacs-version isn't available early, but we really don't care then
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
174 (if (null (boundp 'emacs-version))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
175 "XX.XX"
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
176 (or paths-path-emacs-version ; cache
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
177 (progn
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
178 (string-match "\\`[^0-9]*\\([0-9]+\\.[0-9]+\\)" emacs-version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
179 (let ((version (substring emacs-version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
180 (match-beginning 1) (match-end 1))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
181 (if (string-match "(beta *\\([0-9]+\\))" emacs-version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
182 (setq version (concat version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
183 "-b"
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
184 (substring emacs-version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
185 (match-beginning 1) (match-end 1)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
186 (setq paths-path-emacs-version version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
187 version)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
188
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
189 (defun paths-find-emacs-path (roots suffix base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
190 "Find a path in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
191 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
192 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
193 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
194 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
195 specify the path.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
196 DEFAULT is a fall-back value."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
197 (let ((envvar-value (and envvar (getenv envvar))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
198 (if envvar-value
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
199 (decode-path-internal envvar-value)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
200 (let ((directory (paths-find-emacs-directory roots base suffix)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
201 (if (and directory (file-directory-p directory))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
202 (list directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
203 (paths-directories-which-exist default))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
204
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
205 (defun paths-directories-which-exist (directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
206 "Return the directories among DIRECTORIES."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
207 (let ((reverse-directories '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
208 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
209 (if (file-directory-p (car directories))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
210 (setq reverse-directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
211 (cons (car directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
212 reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
213 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
214 (reverse reverse-directories)))
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-site-path (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
217 "Find a path underneath the site hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
218 (paths-find-emacs-path roots "lib/xemacs/" base envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
219
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
220 (defun paths-find-version-path (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
221 "Find a path underneath the site hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
222 (paths-find-emacs-path roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
223 (concat "lib/xemacs-" (construct-emacs-version) "/")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
224 base
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
225 envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
226
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
227 (defun paths-find-emacs-roots (invocation-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
228 invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
229 "Find all plausible installation roots for XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
230 (let ((invocation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
231 (paths-find-emacs-root invocation-directory invocation-name))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
232 (installation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
233 (if (and configure-prefix-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
234 (file-directory-p configure-prefix-directory))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
235 configure-prefix-directory)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
236 (append (and invocation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
237 (list invocation-root))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
238 (and installation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
239 (list installation-root)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
240
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
241 ;;; find-paths.el ends here