#!/bin/sh
#
# this script will filter the source files in a directory so
# that they use the new naming conventions (i.e. the prepended
# B_ to all constants).  It also converts function names to new
# style function names.  It does not deal with functions that no
# longer exist (such as be_app->IsQuitting()), but you'll find
# out about those as you compile code.
#

echo ""
echo "Converting all source files (*.cpp *.c++ *.cxx *.c *.h)."
echo "Original versions of the files are saved as file.cpp.save."

echo ""
echo "This conversion is slow.  Please be patient."
echo ""

#
# don't want "*.c++" to expand to "*.c++" if there are no matching files
#
allow_null_glob_expansion=1

#
# this is the base part of the sed script file name.
# it was broken into multiple parts so as not to swamp
# small memory machines.
#
base_sed_file=/boot/be/Tools/dr6convert/sedscript

#
# where the sed executable lives
#
sed=/boot/be/Tools/dr6convert/sed

for i in *.cpp *.c++ *.cxx *.c *.h
do
   echo "---------- converting $i ----------------"
   cp $i $i.save

   echo -n Pass 1....
   $sed -f$base_sed_file.1 $i > t

   echo -n Pass 2....
   $sed -f$base_sed_file.2  t > t2

   echo -n Pass 3....
   $sed -f$base_sed_file.3 t2 > t

   echo -n Pass 4....
   $sed -f$base_sed_file.4  t > t2

   echo    Done!
   rm t
   mv t2 $i
done
