#!/bin/sh

# Author: Ben Wing <ben@xemacs.org>

# Find the correspondences between the Lisp files in $1 and $2 and output a
# script to move them appropriately for better CVS'ing.

e1=$1/lisp
e2=$2/lisp

echo "#!/bin/sh"
echo ""
echo "# Generated by $0"
echo ""
echo "# Converts the lisp directory tree in $e1"
echo "# into the arrangement in $e2,"
echo "# for use in CVS merging."
echo ""

cd $e2
for x in * ; do
  if [ -d $x ] ; then
    echo "if ! [ -d $x ] ; then mkdir $x ; fi"
  fi
done

cd $e1
for x in *.el */*.el ; do
  (
    cd $e2
    ## first check if no change
    if [ -e $x ] ; then
      echo "# No change: $x"
    else
      ## then in one of the subdirectories
      new=`basename $x`
      new2=`echo */$new`
      if [ "$new2" = "*/$new" ] ; then
        ## then in the base directory (in case a file from a subdirectory
        ## was moved back to the base directory)
        if [ -e $new ] ; then
          echo "mv $x $new"
        else
          echo "# Can't find: $x"
        fi
      else
        echo "mv $x $new2"
      fi
    fi
  )
done
