2 # emacs-fe --- front end driver for `emacs' and other programs
4 # Copyright (C) 1995, 1996 Noah S. Friedman
6 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
9 # $.Id: emacs-fe,v 1.8 1996/03/07 04:32:33 friedman Exp $
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, you can either send email to this
23 # program's maintainer or write to: The Free Software Foundation,
24 # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
28 # Inspired by a similar set of scripts by Charles Sandel <sandel@cli.com>,
29 # but generalized into this single script.
31 # Front-end shell script for GNU Emacs, used to manage multiple versions of
32 # Emacs and its associated utilities.
34 # Strategy: Install this script as "$prefix/bin/[progname]", for each
35 # program named [progname], (e.g. "emacs", "ispell", "etags", etc). These
36 # are the commands users would normally execute to run them.
38 # Give each version of emacs/xemacs/mule/ispell a separate hierarchy under
39 # $prefix/[emacs|xemacs|mule|ispell], with the name
40 # "[emacs|xemacs|mule|ispell]-NN.NN" where NN.NN is the version number.
41 # This script looks at what versions are available, and selects a version,
42 # currently whatever is specified by $DEFAULTLVERSION.
44 # However, users can specify their own choice to force the selection of a
45 # particular version by setting the environment variable PROGNAMEVERSION
46 # (e.g. EMACSVERSION, MULEVERSION, XEMACSVERSION, etc.) to have a value
47 # which is the version number of the program that they want to use (just
48 # the numeric value), or to specify either the NEWEST or OLDEST versions.
52 # Name by which this script was invoked.
53 progname=`echo "$0" | sed -e 's/[^\/]*\///g'`
55 # To prevent hairy quoting and escaping later.
64 echo "$progname: Exactly one argument is required." 1>&2
69 # sed is more portable than `dirname'
70 dir=`echo "$0" | sed -e 's/\/*$//' -e 's/\/[^\/]*$//'`
71 if test -f "$dir/$1"; then
77 echo "$progname: $bq$dir/$1$eq does not seem to exist." 1>&2
82 DEFAULTVERSION="${DEFAULTVERSION-NEWEST}"
83 VARIANT="${EMACSVARIANT-emacs}"
85 if [ "$prefix" = "" ] ; then
86 # root of the GNU installed tree
90 if [ ! -d "$prefix" ] ; then
91 echo "Cannot find root of GNU tree ($prefix)."
96 emacs | lemacs | xemacs | mule | ispell )
97 if [ "$eprefix" = "" ] ; then
98 # prefix name of the subdirectory
99 eprefix="${progname}/${progname}-"
103 eprefix="$VARIANT/${VARIANT}-"
107 # Find out which versions are available on the system and sort them
110 # The largish sed script prefixes all version numbers with a sort key.
111 # That key is constructed by padding out any single or double digits to 3
112 # digits from the version number, then converting all occurrences of `.' to
113 # `0', and prefixing and suffixing the entire result with an additional
114 # zero. After sorting, the sort key is stripped from the output.
115 # We do all this because `sort' cannot numerically sort decimal numbers and
116 # will stop on the first `.'.
117 # This may not work correctly if the version number has more than 4 levels
118 # of minor versions (e.g. "1.2.3.4.5" may cause problems).
119 availversions=`ls -1d $prefix/${eprefix}*/. 2> /dev/null \
121 -e "s#^$prefix/$eprefix\([0-9.][0-9.]*\)/\.*#\1#" \
123 s/[^.]*[^0-9.][^.]*\.//g
125 /[0-9.][0-9.]*\.[0-9.][0-9.]*\.[0-9.][0-9.]*\.[0-9.][0-9.]*/!{
132 s/\.\([0-9]\)\./.00\1./g
133 s/\.\([0-9][0-9]\)\./.0\1./g
142 if [ "$availversions" = "" ] ; then
143 echo "No version of $progname found in $prefix/$eprefix*."
147 # This sets `oldest' to the oldest version available, and `newest'
148 # to the newest version available.
149 # On line 1, we save the original pattern in the hold space and restore it
150 # in case it is the only line of input.
151 eval `echo "$availversions" \
152 | sed -ne '1{h;s/^/oldest=/p;g;}
156 # The environment variable [progname]VERSION can have a value which specifies
157 # a version number, OR it can contain the values "NEWEST" or "OLDEST" to
158 # specify the newest or oldest version which was found.
159 sed_upcase='y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
161 PROGNAME=`echo "$progname" | sed -e "$sed_upcase" -e 's/-/_/g'`
162 eval version=\"\$${PROGNAME}VERSION\"
164 # If there is no ETAGSVERSION, EMACSCLIENTVERSION, etc, then look for
165 # EMACSVERSION, XEMACSVERSION, or whatever the current variant is.
170 # If this is ispell and ISPELLVERSION isn't set, just use 3.1.
171 # We could run this script recursively with a flag indicating to
172 # find the current emacs variant and version and just print it out,
173 # but that is a very pathological case and is a lot of work.
176 variant=`echo "$VARIANT" | sed -e "$sed_upcase"`
177 eval version=\"\$${variant}VERSION\"
179 '' ) version="$DEFAULTVERSION" ;;
186 [Oo][Ll][Dd][Ee][Ss][Tt]) version="$oldest" ;;
187 [Nn][Ee][Ww][Ee][Ss][Tt]) version="$newest" ;;
188 '') version="$oldest" ;;
190 if [ ! -d "$prefix/$eprefix$version" ] ; then
191 echo "$progname: $version: Cannot find requested version." 1>&2
197 # If we don't have a version by now, then give up.
198 if [ "$version" = "" ] ; then
200 echo "$progname: Cannot determine which version to use."
201 case "$availversions" in
203 echo "Available versions are:"
204 for f in $availversions; do
209 echo "Available versions are:" $availversions
216 emacs | lemacs | xemacs | mule )
217 EMACSVARIANT=$progname
218 eval ${PROGNAME}VERSION=$version
219 eval export EMACSVARIANT ${PROGNAME}VERSION
221 case "$EMACSVARIANT-$version" in
222 emacs-18* ) ISPELLVERSION=4.0 ;;
223 emacs-19.[0-9] ) ISPELLVERSION=4.0 ;;
224 emacs-19.1[0-9] ) ISPELLVERSION=4.0 ;;
225 emacs-19.2[0-2] ) ISPELLVERSION=4.0 ;;
226 emacs-19.2[3-9] ) ISPELLVERSION=3.1 ;;
227 emacs-* ) ISPELLVERSION=3.1 ;;
229 lemacs-19.[0-9] ) ISPELLVERSION=3.0.09 ;;
230 lemacs-19.10 ) ISPELLVERSION=3.1 ;;
232 xemacs-* ) ISPELLVERSION=3.1 ;;
234 mule-* ) ISPELLVERSION=3.1 ;;
242 # xemacs expects to use the keysym database in /usr/openwin, but that
243 # database doesn't define many of the keysyms it uses. Unless the user
244 # has already defined their own, specify the keysym database in X11.
245 XKEYSYMDB="${XKEYSYMDB-/usr/local/X11/lib/X11/XKeysymDB}"
248 # Some versions of xemacs (e.g. 19.12) are dynamically linked against
249 # the openwin tooltalk library (libtt.so), so add openwin to the
250 # dynamic load path if necessary.
251 case "$LD_LIBRARY_PATH" in
252 *'/usr/openwin/lib'* ) : ;;
254 LD_LIBRARY_PATH=/usr/local/X11R5/lib:/usr/openwin/lib:/lib
255 export LD_LIBRARY_PATH
258 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/openwin/lib"
259 export LD_LIBRARY_PATH
265 # Set up the MANPATH so that the man pages for this version
267 if [ -d $prefix/$eprefix$version/man ] ; then
268 MANPATH=$prefix/$eprefix$version/man:$MANPATH
272 # There is no need to do this, and it can potentially cause problems,
273 # especially if a program like `xemacs' exists in that directory and gets
274 # run in subshells instead of this script.
275 #PATH=$prefix/$eprefix$version/bin:$PATH
278 searchdirs=`exec 2> /dev/null
279 cd $prefix/$eprefix$version \
281 libexec/$VARIANT/$version/* \
282 lib/$VARIANT/$version/* \
283 lib/$VARIANT-$version/* \
288 for dir in $searchdirs ; do
289 for p in $progname-$version $progname ; do
290 prog="$prefix/$eprefix$version/$dir/$p"
292 if test -f "$prog" ; then
293 case "${EMACS_FE_PRINT+set}" in
300 exec "$prog" ${1+"$@"}
307 echo "$progname: Cannot find $bq$progname-$version$eq or $bq$progname$eq in"
309 for d in $searchdirs ; do
310 ls -1d $prefix/$eprefix$version/$d 2> /dev/null \
311 | sed -e "s/^/$progname: /"