#! /bin/sh
#
# $Id: import-emacs,v 1.2 2001/12/01 08:19:32 wohler Exp $
#
# NAME
#   import-emacs - import mh-e changes from Emacs baseline
#
# SYNOPSIS
#   make import
#   --or--
#   import-emacs
#
# DESCRIPTION
#   Imports the mh-e changes from the Emacs baseline into the current
#   mh-e sources. This should be invoked as "make import."
#
# OPTIONS
#   --debug
#     Turn on debugging messages.
#
#   --help
#     Display the usage of this command.
#
#   --version
#     Display program version.
#
# RETURN VALUE
#
# EXAMPLES
#
# ENVIRONMENT
#   MHE_HOME
#     Location of mh-e development tree. Default is current directory.
#
#   EMACS_HOME
#     Location of Emacs development tree. Default is /usr/local/src/mh-e/src.
#
# FILES
#
# SEE ALSO
#
# VERSION
#   $Revision: 1.2 $
#
# AUTHOR
#   Bill Wohler <wohler@newt.com>
#
#   Copyright (C) 2001  Newt Software
#   
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, you can find it at
#   http://www.gnu.org/copyleft/gpl.html or write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# Initializations.

# Constants.
cmd=`basename $0`                       # name by which command called
MHE_HOME=${MHE_HOME:-`pwd`}
EMACS_HOME=${EMACS_HOME:-/usr/local/src/emacs}
export CVSROOT=`cat $MHE_HOME/CVS/Root`

# Program version: start with CVS version, strip dollar signs, CVS keyword
# and whitespace.
ver=`echo '$Revision: 1.2 $' | sed -e 's/\\$//g' -e 's/Revision://' -e 's/ //g'`

# Variables (may be overridden by arguments).
debug=0                                 # verbose mode
exitstatus=0                            # upon error, set to non-zero and exit
interrupt=0                             # upon interrupt, set to 1

# Functions.

# Display usage information and exit.
usage() {
    cat <<EOF
Usage: $cmd [options]
--debug                 print actions that program takes
--help                  display this message
--version               display program version
EOF
    bye 1;
}

# Exit gracefully.
# Usage: bye [(status [message]]
bye() {
    if [ $# -gt 0 ]; then
        exitstatus=$1
        shift
    fi
    if [ $# -gt 0 ]; then
        echo "$*"
    elif [ $interrupt -eq 1 ]; then
        echo ""
    fi
    exit $exitstatus
}

# Handle an interrupt.
intr() {
    echo ""
    interrupt=1
    bye 1
}

# Display version information and exit.
show_version() {
    cat <<EOF
$cmd version $ver
Copyright (C) Bill Wohler <wohler@newt.com>

$cmd comes with ABSOLUTELY NO WARRANTY.

This is free software, and you are welcome
to redistribute it under certain conditions.

See http://www.gnu.org/copyleft/gpl.html for details.
EOF
    exit 0;
}

# Parse command line.
while [ $# != 0 ]; do
    case "$1" in
    --d*)       debug=1;;
    --h*)       usage;;
    --v*)       show_version;;
    -*)         usage;;
    *)          break;;
    esac
    shift
done

trap intr 2

# Calculate release.
cd $EMACS_HOME
release=`cvs status lisp/mail/mh-e.el    | \
	 awk '/Sticky Tag/{print $3}'    | \
	 sed -e 's/EMACS_/emacs-/' -e 's/(none)/mainline/'`

# Grab files.
cd $MHE_HOME || return 1
rm -rf t
mkdir t || return 1
cd t
cp $EMACS_HOME/COPYING .
cp $EMACS_HOME/lisp/mail/mh-*.el .
cp $EMACS_HOME/etc/MH-E-NEWS .

# Import and update.
cvs -d $CVSROOT import -m "$release" src emacs $release
cd ..
rm -rf t
cvs update -jemacs:yesterday -jemacs

bye
