I have moved my classes from a global namespace into a specific namespace. I have also changed the class names. I want to convert all my source files that use these classes to the new format. I was thinking either a bash
script using a sed
file on Cygwin or executing a perl script. I'm having troubles with the bash
script.
Here's the process I'm trying to perform:
- For each source file, *.cpp and *.hpp, recursively:
- If the file contains an old class name, then convert the file.
- End for.
My problem in Bash
script is detecting if the file contains an old class name. I was thinking of one grep
statement for each class name:
for f in `find . -iname \*.[ch]pp`;
do
if [ grep "Field_Blob_Medium" $f -eq 0 || grep "Field_Boolean" ]; then
sed -f conversion.sed $f
fi
done
An issue is that only one command can be in Bash
if statement, using this syntax:
if grep "Field_Unsigned_Short" $f;
so I can't do a logical OR of grep
s.
I could perform a nested loop, but I don't know how to break
out of a Bash
for loop:
OLD_CLASS_NAMES="Field_Blob_Medium Field_Boolean Field_Unsigned_Int"
for f in `find . -iname \*.[ch]pp`;
do
for c_name in $OLD_CLASS_NAMES;
do
if grep $c_name $f then
sed -f convert.sed $f # <-- Need to break out of inner loop after this execution.
fi
done
done
So I'm looking for suggestions on how to process every source file that contains old class names and convert them to new ones. A Cygwin Bash
script example is preferred, although a Perl script would also be acceptable. Also, the script should make a backup copy of the original source file before writing the converted contents out to the new
file.
I'm running Cygwin on Windows XP and Windows Vista.