-#
-# Useage:
-# chbar file1 file2 [output]
-# (default output is stdout)
-# chbar old
-# (new file on stdin, output on stdout)
-#
-# Method:
-# 1 Use diff to get an ed script to go from file1 to file2.
-# 2 Breathe on it a bit (with sed) to insert changebar commands.
-# 3 Apply modified ed script to produce (nearly) the output.
-# 4 Use awk to insert the changebars option into the \documentstyle
-# and to handle changebar commands inside verbatim environments.
-# 5 Remove changebars before \begin{document} with sed
-if test $# -eq 0
-then cat <<\xEOF
-Useage:
- chbars old new [output]
- chbars old
-xEOF
-exit 0
+# v1.2 Aug 95 Added support for LaTeX209/LaTeX2e
+# Added RCS support to retrive old files
+
+CMD=`basename $0`
+
+SED=sed
+RM="rm -f"
+DIFF=diff
+ED=ed
+AWK=awk
+GREP=grep
+MV=mv
+CAT=cat
+MKDIR=mkdir
+CO="co"
+
+TMPDIR=${TMP-/tmp}/$CMD.$$
+trap 'test $DEBUG = NO && rm -rf $TMPDIR' 0 1 2 3 6 7 13 15
+mkdir $TMPDIR || { echo "cannot create directory \`$TMPDIR'." >&2; exit 1; }
+TMPFILE=${TMPDIR}/$CMD.$$
+SED_CMD_FILE=$TMPFILE.sed
+
+usage()
+{
+$CAT << _END_
+Usage:
+ $CMD [-hgG] [-d dir] old new [output]
+ default output is stdout
+
+ $CMD [-hgG] [-d dir] old
+ new file on stdin, output on stdout
+
+ $CMD [-hgG] -d dir -r rev files
+ old file retrieved using RCS
+
+ Gadget to take two LaTeX files and produce a third which
+ has changebars highlighting the difference between them.
+ Changebars are inserted for differences after '\begin{document}'.
+
+ Feature: \`new' can not be named \`-'.
+
+ Options are:
+ -d dir : Write the output to file \`dir/new', if \`new' is given or
+ to file \`dir/old'.
+ If \`dir' does not exist, it is created.
+ If \`output' is given, it is discarded.
+
+ -r rev : If the LaTeX \`files' are kept under control of the
+ Revision Control System RCS, the old files of
+ the revision \`rev' can be retrived.
+ \`rev' is specified using the RCS conventions.
+ This option must be used together with the \`-d dir' option.
+ \`files' must be a nonempty list of files.
+
+ -h : Print this info text.
+ -g : Print some debugging info.
+ -G : Even more debug info.
+
+ Version 1.2: August 3. 1995
+_END_
+exit 1
+}
+
+# parse options and arguments
+DEBUG="NO"
+DIR=
+REV=
+# process options
+while getopts d:r:gGh i $*
+do
+ case $i in
+ d ) DIR=$OPTARG;;
+ r ) REV=$OPTARG;;
+ g ) DEBUG="YES" ;;
+ G ) set -x; DEBUG="YES";;
+ h | \
+ * ) usage ;;
+ esac
+done
+
+shift `expr $OPTIND - 1`
+
+case $# in
+ 1 ) OLD=$1; NEW="-"; OUT="" ;;
+ 2 ) OLD=$1; NEW=$2; OUT="" ;;
+ 3 ) OLD=$1; NEW=$2; OUT="$3" ;;
+ * ) usage ;;
+esac
+
+# check correct options
+if [ ! -z "$DIR" ]
+then
+ [ -d $DIR ] || $MKDIR $DIR