#!/bin/sh

if [ ! -d "tzdata/dump" ]; then
   echo "Dump files removed."
   exit
fi

for file in `cd tzdata/dump; echo *` ;do
   tz=`head -1 tzdata/dump/$file | awk '{print $1}'`
   echo "##########################################################"
   echo "### $tz"

   # Create the new dump
   examples/dm_zdump -v $tz | tail --lines=+2 > z.dump.new
   ln=`wc -l z.dump.new | awk '{print $1}'`

   # Copy the old dump
   tail --lines=+3 tzdata/dump/$file | head --lines=-2 > z.dump.old
   lo=`wc -l z.dump.old | awk '{print $1}'`

   if [ "$ln" = "0" ]; then
      echo "***"
      echo "*** ERROR ***"
      echo "***"

   elif [ $lo -gt $ln ]; then
      mv z.dump.old z.dump.old.1
      head --lines=$ln z.dump.old.1 > z.dump.old
      rm -f z.dump.old.1

   elif [ $ln -gt $lo ]; then
      mv z.dump.new z.dump.new.1
      head --lines=$lo z.dump.new.1 > z.dump.new
      rm -f z.dump.new.1
   fi

   diff -c z.dump.old z.dump.new
   rm -f z.dump.old z.dump.new

done

