#!/bin/sh


#
# Designed to work with the "ednew" script, to check whether edits were made
# without using ednew.  This is really pretty lame, but it's better than
# nothing.
#
# This code copyright October 1998 by
# W.M. Richards, NiEstu, Phoenix, AZ -- chipr@niestu.com
#
# This software is made freely available under the provisions of the Perl
# "Artistic" license:  http://language.perl.com/misc/Artistic.html
#
# This code is not supported and is not warranteed to perform any particular
# function. Contact chipr@niestu.com for aditional information.
# If you find bugs or make enhancements, it would be appreciated if you
# sent them on to the author at chipr@niestu.com.
#
# Usage: cd to top-level directory, run "checkeds".  Will run find and
# re-invoke itself with the "-c" argument to check a suspect file.  You may
# also give the "-v" option, for verbose operation--this will print a message
# for all files it checks, not just those with missing ".original" files.
#

#
# Configuration
suffix="original"
backups="~ .bak"

#
# Function to check for a single backup suffix
function check_suffix
{
   bkup="$1"
   find . -name "*$bkup" -exec $0 $verbose -c "{}" "$bkup" ";"
}

#
# See if the "verbose" (-v) option was given
verbose=""
if [ "$1" = "-v" ]; then
   verbose="-v"
   shift
fi

#
# If we are in "check" mode, see if the file has an original
if [ "$1" = "-c" ]; then
   file="$2"
   bkup="$3"
   base="${file%%$bkup}"
   if [ ! -e "$base.$suffix" ]; then
      echo "*** File \"$file\" exists, but \"$base.$suffix\" does not"
   else
      if [ ! -z "$verbose" ]; then
         echo "File \"$file\" has a corresponding \"$base.$suffix\""
      fi
   fi

#
# Not in "check" mode--check each backup suffix in turn
else
   for bkup in $backups ; do
      check_suffix "$bkup"
   done
fi
