#!/bin/sh

# mfen

# Compare revisions of documentation of different languages.
# It is mainly used to check which files should be merged from
# or have incorrent revision information.

# Here is how to use this:
#
# $ mfen en_US.ISO8859-1 hu_HU.ISO8859-2

# Copyright 2008 The FreeBSD Hungarian Documentation Project
# Created by: PALI, Gabor <pgj@FreeBSD.org>


PATH=/bin:/usr/bin:/usr/sbin

CVS_ID_TAG=FreeBSD

traverse() {
  for j in `ls $2`; do
    if [ -d $2/$j ]; then
      traverse $1/$j $2/$j $3$j/
    else
      TR=`grep Original\ Revision $2/$j`
      if [ -n "$TR" ]; then
        if [ -f "$1/$j" ]; then
          LG=`grep "[$]$CVS_ID_TAG:" $1/$j`
          if [ -n "$LG" ]; then
            FROM=`echo $TR | awk '{print substr($0, index($0, "1.") + 2, 6)}' | awk '{print $1}'`
            TO=`echo $LG | awk '{print substr($0, index($0, "1.") + 2, 6)}' | awk '{print $1}'`
            if [ $FROM -lt $TO ]; then
              printf "1.%-4d --> 1.%-4d  %s\n" $FROM $TO $3$j
            elif [ $FROM -gt $TO ]; then
              printf "REVISION ERROR     %s\n" $3$j
            fi
          fi
        else
          printf "NOT FOUND          %s\n" $3$j
        fi
      fi
    fi
  done
}

if [ -n "$1" ] && [ -n "$2" ]; then
  traverse $1 $2 ""
else
  echo USAGE: $0 "directory1" "directory2"
fi
