#!/bin/sh

find $FOAM_SRC $FOAM_APP -name "*.H" -type f | while read line
do

  fileName=$(basename $line)
  correctMangledName=$(basename $line | sed 's=\.=_=')
  
  if grep -q "#ifndef.*_H" $line
  then
    if ! grep "#ifndef.*_H" $line | grep -q $correctMangledName
    then
      grep -H "#ifndef" $line

      currentMangled=$(grep "#ifndef.*_H" $line | sed 's=#ifndef\s*==')
      
      sed -i -e 's='$currentMangled'='$correctMangledName'=' $line
    fi
  fi

done
