-###--------------------------------------------------------------------------
-### Utility functions.
-
-## __mdw_addto VAR DIR PATH ...
-##
-## VAR is the name of a PATH-like environment variable (i.e., one which
-## contains a sequence of pathnames separated by colons). DIR is either `l'
-## or `r'. The PATHs are pathnames. Those PATHs which correspond to
-## existing directories but which aren't currently named in the variable are
-## added to the left or right (depending on DIR) of VAR. The relative order
-## of PATHs added in the same invokation is the same as the order they
-## appeared in PATHs: the DIR argument only affects which end of the VAR they
-## get added to.
-__mdw_addto () {
- local var=$1 val dir=$2 new="" change=nil
- eval "val=\$$var"
- shift 2
- for i in "$@"; do
- case "$new:" in *:$i:*) continue;; esac
- [ -d $i ] || continue
- case "X$val" in
- X) val=$i change=t continue ;;
- X$i) continue ;;
- X*:$i:*) val=`echo $val | sed -e "s=:$i:=:="` ;;
- X$i:*) val=${val#$i:} ;;
- X*:$i) val=${val%:$i} ;;
- esac
- new=$new:$i change=t
- done
- case $dir in
- l) val=${new#:}:$val ;;
- r) val=$val$new ;;
- esac
- case $change in t) export $var="$val" ;; esac
-}
-
-## __mdw_programp NAME
-##
-## Does NAME exist as an executable program?
-__mdw_programp () { type -t >/dev/null "$1"; }
-
-###--------------------------------------------------------------------------
-### Other preliminaries.
-
-## Work out my home directory.
-##
-## This horrible trick resolves symbolic links. It enables resolving links,
-## changes directory and displays the name of the directory in a subshell to
-## avoid changing the current state.
-HOME=`(set -P; cd $HOME; pwd)`
-[ -n "$SCHROOT_SESSION_ID" ] || cd $HOME
-
-## CDE's session structure is demented and doesn't leave us with a proper
-## logout hook, so synthesize one here.
-[ -n "$DT" ] && trap "source $HOME/.bash_logout" EXIT
-
-###--------------------------------------------------------------------------
-### Set some basic paths.
-
-## The main path.
-__mdw_addto PATH l \
- $HOME/bin \
- {/usr{/local,}{,/X11R6},}{/bin,/sbin,/games} \
- /opt/nfast{,/gcc}{/bin,/sbin} \
- $HOME/src/ncipher/scripts
-
-## If we have Plan 9 from User Space, then add that in.
-if [ -d /usr/local/plan9 ]; then
- export PLAN9=/usr/local/plan9
- __mdw_addto PATH r \
- $PLAN9/bin
-fi
-
-## Search for `info' documents.
-__mdw_addto INFOPATH r \
- $HOME/info \
- /usr/info /usr/share/info \
- /usr/local/info /usr/local/share/info \
- /usr/local/share/info/its
-
-## Script libraries.
-__mdw_addto PERLLIB r $HOME/lib/perl
-__mdw_addto PYTHONPATH r $HOME/lib/python
-
-###--------------------------------------------------------------------------
-### Various other kinds of configuration.
-
-__mdw_setconf () {
- if val=$(mdw-conf 2>/dev/null "$2"); then
- eval "export $1=\$val"
- fi
-}
-
-## Establish a temporary directory.
-[ "$TMPDIR" ] || eval `tmpdir -b`
-export TMP=$TMPDIR
-
-## Sensible umask if users have their own groups.
-umask 002
-
-## Mail and general identification.
-__mdw_setconf MAIL mailbox
-export NAME="Mark Wooding"
-__mdw_setconf EMAIL email
-export QMAILINJECT=c
-
-## Some programs want to know the hostname.
-[ -z "$HOST" ] && export HOST=`hostname`
-
-## Text editor configuration.
-export MDW_EDITOR=ed
-emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
-for ed in \
- "emacs23 $emacs_startup_args" \
- "emacs24 $emacs_startup_args" \
- "emacs22 $emacs_startup_args" \
- "emacs21 $emacs_startup_args" \
- zile mg \
- "emacs -nw" \
- vi pico nano ae; do
- name=`echo $ed | sed 's/ .*$//'`
- if __mdw_programp "$name"; then
- MDW_EDITOR=$ed
- break
- fi
-done
-export EDITOR=mdw-editor VISUAL=mdw-editor
-
-## Determine the locale settings. Really don't set LC_COLLATE because it
-## messes with the order of files in `ls' listings and similar.
-if [ "$DISPLAY" != "" ]; then
- LANG=`mdw-conf x-ctype POSIX`
-else
- : ${LANG=${LC_CTYPE-${LC_ALL-`mdw-conf console-ctype POSIX`}}}
- case "$TERM,`tty`" in
- linux,/dev/tty*)
- if { vt-is-UTF8 ||
- kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
- ctype=.utf8
- else
- ctype=
- fi
- LANG=${LANG%.*}$ctype
- ;;
- esac
-fi
-unset LC_ALL
-export LC_COLLATE=POSIX LANG
-
-## Pager configuration.
-export MDW_PAGER=`type -p less` PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
-export LESS="-iqgRh1j.3FSX"
-export LESSOPEN="|lesspipe.sh %s"
-case "${LC_CTYPE-$LANG}" in
- *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
- *) LESSCHARSET=latin1 ;;
-esac
-export LESSCHARSET
-__mdw_programp global && export LESSGLOBALTAGS=global
-
-## HTTP and FTP proxies.
-http=`mdw-conf http-proxy none`
-case "${http_proxy-none},$http" in
- *,none) ;;
- none,*) export http_proxy=http://$http/ ;;