:
# Script to help checking `recode'.
# Copyright (C) 1991 Free Software Foundation, Inc.
# Francois Pinard <pinard@iro.umontreal.ca>, 1991.

# 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, 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Use this script by `checkit [-v] FILE BEFORE AFTER'.  It does
# various check of recoding FILE from BEFORE to AFTER or vice-versa.
# The -v parameter gives more verbose output.  Exit with a non-zero
# status if any error found.

if test "$1" = -v; then
  shift
  verbose=1
fi

# Select methods to be tested by studying `configure' output.

eval `grep '^DEFS=' config.status`
methods=i
case "$DEFS" in
  *HAVE_POPEN*) methods="$methods o" ;;
esac
case "$DEFS" in
  *HAVE_PIPE*) methods="$methods p" ;;
esac

# Echo the tested sequence of steps.

if test -n "$verbose"; then
  ./recode -vi < /dev/null $2:$3
  ./recode -vi < /dev/null $3:$2
fi

# Try all methods, both in filter and in non-filter modes.

for method in $methods; do
  test -n "$verbose" && echo "Checking -$method between $2 and $3 on stdin"
  ./recode -$method < $1 $2:$3 | ./recode -$method $3:$2 > checkit.tmp
  if diff $1 checkit.tmp; then
    :
  else
    echo
    echo "*** error in: recode -$method < $1 $2:$3  [or $3:$2]"
    rm checkit.tmp
    exit 1
  fi

  test -n "$verbose" && echo "Checking -$method between $2 and $3 on file"
  cp $1 checkit.tmp
  ./recode -$method $2:$3 checkit.tmp
  ./recode -$method $3:$2 checkit.tmp
  if diff $1 checkit.tmp; then
    :
  else
    echo
    echo "*** error in: recode -$method   $1 $2:$3  [or $3:$2]"
    rm checkit.tmp
    exit 1
  fi
done

# Return success.

rm checkit.tmp
exit 0
