#!/bin/sh
# $Id: original 1.0 1995/04/26 17:29:19 jerry book3 $
#
### original - Replace mhn-edited draft with original containing directives
### Usage:  What now? edit original
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


t=','   # CHARACTER mhn PREPENDS TO DRAFT FILENAME TO MAKE IT "TEMPORARY"

# $mhdraft HAS DRAFT PATHNAME.  IF NOT SET, PRINT TWO-LINE ERROR AND EXIT:
: ${mhdraft?"aborting: mhdraft not set in environment.
Be sure that you're using this from a 'What now?' prompt."}

# PUT DRAFT DIRECTORY IN $dir, DRAFT FILE IN $file:
eval `echo "$mhdraft" | sed 's@\(.*\)/\(.*\)@dir="\1" file="\2"@'`

cd "$dir" || {
    echo "`basename $0` aborting: can't cd to draft directory '$dir'?" 1>&2
    exit 1
}

case "$file" in
draft|[1-9]*) orig="$t$file.orig" ;;
*)  echo "`basename $0` aborting: invalid draft filename '$file'?" 1>&2
    exit 1
    ;;
esac

if test ! -r "$file" -o ! -r "$orig" -o ! -w "$file"
then
    echo "`basename $0` aborting: can't read draft '$orig' and/or read/write '$file'" 1>&2
    exit 1
fi

/bin/mv "$file" "$t$file.mhn" || {
    echo "`basename $0` aborting: can't rename '$file' to '$t$file.mhn'?" 1>&2
    exit 1
}

/bin/mv "$orig" "$file" || {
    echo "`basename $0` aborting: can't rename '$orig' to '$file'?" 1>&2
    exit 1
}
