annotate lisp/find-paths.el @ 274:ca9a9ec9c1c1 r21-0b35

Import from CVS: tag r21-0b35
author cvs
date Mon, 13 Aug 2007 10:29:42 +0200
parents c5d627a313b1
children 6330739388db
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
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
77 (file-directory-p (concat directory "lib/xemacs"))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
78 ;; in-place
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
79 (and
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
80 (file-directory-p (concat directory "lib-src"))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
81 (file-directory-p (concat directory "lisp"))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
82 (file-directory-p (concat directory "src")))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
83
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
84 (defun paths-chase-symlink (file-name)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
85 "Chase a symlink until the bitter end."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
86 (let ((maybe-symlink (file-symlink-p file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
87 (if maybe-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
88 (let* ((directory (file-name-directory file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
89 (destination (expand-file-name maybe-symlink directory)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
90 (paths-chase-symlink destination))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
91 file-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
92
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
93 (defun paths-find-emacs-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
94 (invocation-directory invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
95 "Find the run-time root of XEmacs."
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
96 (let* ((executable-file-name (paths-chase-symlink
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
97 (concat invocation-directory
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
98 invocation-name)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
99 (executable-directory (file-name-directory executable-file-name))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
100 (maybe-root-1 (file-name-as-directory
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
101 (expand-file-name ".." executable-directory)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
102 (maybe-root-2 (file-name-as-directory
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
103 (expand-file-name "../.." executable-directory))))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
104 (or (and (paths-emacs-root-p maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
105 maybe-root-1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
106 (and (paths-emacs-root-p maybe-root-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
107 maybe-root-2))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
108
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
109 (defun paths-construct-emacs-directory (root suffix base)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
110 "Construct a directory name within the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
111 (file-name-as-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
112 (expand-file-name
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
113 (concat
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
114 (file-name-as-directory root)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
115 suffix
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
116 base))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
117
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
118 (defun paths-find-emacs-directory (roots suffix base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
119 "Find a directory in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
120 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
121 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
122 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
123 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
124 specify the directory.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
125 DEFAULT is a fall-back value."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
126 (let ((envvar-value (and envvar (getenv envvar))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
127 (if (and envvar-value
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
128 (file-directory-p envvar-value))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
129 (file-name-as-directory envvar-value)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
130 (catch 'gotcha
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
131 (while roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
132 (let* ((root (car roots))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
133 (path (paths-construct-emacs-directory root suffix base)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
134 ;; installed
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 (let ((path (paths-construct-emacs-directory root "" base)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
138 ;; in-place
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
139 (if (file-directory-p path)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
140 (throw 'gotcha path)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
141 (setq roots (cdr roots)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
142 (if (and default
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
143 (file-directory-p default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
144 (file-name-as-directory default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
145 nil)))))
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-site-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
148 "Find a site-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
149 (paths-find-emacs-directory roots "lib/xemacs/" base envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
150
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
151 (defun paths-find-version-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
152 "Find a version-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
153 (paths-find-emacs-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
154 (concat "lib/xemacs-" (construct-emacs-version) "/")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
155 base
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
156 envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
157
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
158 (defun paths-find-architecture-directory (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
159 "Find an architecture-specific directory in the XEmacs hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
160 (or
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
161 ;; from more to less specific
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
162 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
163 (concat base system-configuration)
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
164 envvar)
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
165 (paths-find-version-directory roots
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
166 base
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 267
diff changeset
167 envvar)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
168 (paths-find-version-directory roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
169 system-configuration
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
170 envvar default)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
171
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
172 (defvar paths-path-emacs-version nil
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
173 "Emacs version as it appears in paths.")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
174
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
175 (defun construct-emacs-version ()
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
176 "Construct the raw version number of XEmacs in the form XX.XX."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
177 ;; emacs-version isn't available early, but we really don't care then
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
178 (if (null (boundp 'emacs-version))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
179 "XX.XX"
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
180 (or paths-path-emacs-version ; cache
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
181 (progn
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
182 (string-match "\\`[^0-9]*\\([0-9]+\\.[0-9]+\\)" emacs-version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
183 (let ((version (substring emacs-version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
184 (match-beginning 1) (match-end 1))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
185 (if (string-match "(beta *\\([0-9]+\\))" emacs-version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
186 (setq version (concat version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
187 "-b"
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
188 (substring emacs-version
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
189 (match-beginning 1) (match-end 1)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
190 (setq paths-path-emacs-version version)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
191 version)))))
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-emacs-path (roots suffix base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
194 "Find a path in the XEmacs hierarchy.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
195 ROOTS must be a list of installation roots.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
196 SUFFIX is the subdirectory from there.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
197 BASE is the base to look for.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
198 ENVVAR is the name of the environment variable that might also
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
199 specify the path.
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
200 DEFAULT is a fall-back value."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
201 (let ((envvar-value (and envvar (getenv envvar))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
202 (if envvar-value
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
203 (decode-path-internal envvar-value)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
204 (let ((directory (paths-find-emacs-directory roots base suffix)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
205 (if (and directory (file-directory-p directory))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
206 (list directory)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
207 (paths-directories-which-exist default))))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
208
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
209 (defun paths-directories-which-exist (directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
210 "Return the directories among DIRECTORIES."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
211 (let ((reverse-directories '()))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
212 (while directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
213 (if (file-directory-p (car directories))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
214 (setq reverse-directories
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
215 (cons (car directories)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
216 reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
217 (setq directories (cdr directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
218 (reverse reverse-directories)))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
219
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
220 (defun paths-uniq-append (list-1 list-2)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
221 "Append LIST-1 and LIST-2, omitting duplicates."
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
222 (let ((reverse-survivors '()))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
223 (while list-2
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
224 (if (null (member (car list-2) list-1))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
225 (setq reverse-survivors (cons (car list-2) reverse-survivors)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
226 (setq list-2 (cdr list-2)))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
227 (append list-1
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
228 (reverse reverse-survivors))))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
229
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
230 (defun paths-find-site-path (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
231 "Find a path underneath the site hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
232 (paths-find-emacs-path roots "lib/xemacs/" base envvar default))
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-find-version-path (roots base &optional envvar default)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
235 "Find a path underneath the site hierarchy."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
236 (paths-find-emacs-path roots
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
237 (concat "lib/xemacs-" (construct-emacs-version) "/")
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
238 base
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
239 envvar default))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
240
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
241 (defun paths-find-emacs-roots (invocation-directory
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
242 invocation-name)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
243 "Find all plausible installation roots for XEmacs."
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
244 (let ((invocation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
245 (paths-find-emacs-root invocation-directory invocation-name))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
246 (installation-root
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
247 (and configure-prefix-directory
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
248 (file-directory-p configure-prefix-directory)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
249 (file-name-as-directory configure-prefix-directory))))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
250 (append (and invocation-root
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
251 (list invocation-root))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
252 (and installation-root
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
253 (paths-emacs-root-p installation-root)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
254 (list installation-root)))))
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
255
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents:
diff changeset
256 ;;; find-paths.el ends here