#! /bin/csh -f

#
# difffsfast
#
# Original Author: Doug Greve
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2007/01/09 22:41:17 $
#    $Revision: 1.2 $
#
# Copyright (C) 2002-2007,
# The General Hospital Corporation (Boston, MA). 
# All rights reserved.
#
# Distribution, usage and copying of this software is covered under the
# terms found in the License Agreement file named 'COPYING' found in the
# FreeSurfer source code root directory, and duplicated here:
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense
#
# General inquiries: freesurfer@nmr.mgh.harvard.edu
# Bug reports: analysis-bugs@nmr.mgh.harvard.edu
#


if($#argv != 2 && $#argv != 3) then
  echo "USAGE: difffsfast fs1 fs2 <showdiff>"
  exit 1;
endif

set fs1 = $argv[1];
set fs2 = $argv[2];
if($#argv == 3) then
  set showdiff = 1;
else
  set showdiff = 0;
endif

# Check each file in fs1 toolbox against that in fs2
foreach m1 ($fs1/toolbox/*.m)
  set b = `basename $m1`;
  set m2 = $fs2/toolbox/$b
  if(! -e $m2) then
    echo "----------------------------------------"
    echo "$b exists in $fs1 but not in $fs2"
  else
    set n = `diff -b -B  $m1 $m2 | wc -l` 
    if($n != 0) then
      echo "----------------------------------------"
      echo "$b differs"
      if($showdiff) diff -b -B  $m1 $m2 
    endif
  endif
end

# Check each file in fs2 toolbox against that in fs1
# existence only
foreach m2 ($fs2/toolbox/*.m)
  set b = `basename $m2`;
  set m1 = $fs1/toolbox/$b
  if(! -e $m1) then
    echo "----------------------------------------"
    echo "$b exists in $fs2 but not in $fs1"
  endif
end

# Check each file in fs1 bin against that in fs2
foreach m1 ($fs1/bin/*)
  if(-d $m1) continue;
  set b = `basename $m1`;
  set m2 = $fs2/bin/$b
  if(! -e $m2) then
    echo "----------------------------------------"
    echo "$b exists in $fs1 but not in $fs2"
  else
    set n = `diff -b -B  $m1 $m2 | wc -l` 
    if($n != 0) then
      echo "----------------------------------------"
      echo "$b differs"
      if($showdiff) diff -b -B  $m1 $m2 
    endif
  endif
end

# Check each file in fs2 bin against that in fs1
# existence only
foreach m2 ($fs2/bin/*)
  if(-d $m2) continue;
  set b = `basename $m2`;
  set m1 = $fs1/bin/$b
  if(! -e $m1) then
    echo "----------------------------------------"
    echo "$b exists in $fs2 but not in $fs1"
  endif
end

echo "----------------------------------------"


exit 0
