File indexing completed on 2024-11-17 05:08:35

0001 #!/bin/sh
0002 
0003 if [ $# != 2 ]; then
0004     echo "Usage: $0 old_classname new_classname"
0005     exit 1
0006 fi
0007 
0008 oldname=$1
0009 newname=$2
0010 
0011 if [ -f $oldname.cpp ]; then
0012     oldfile=$oldname
0013     newfile=$newname
0014 else
0015     oldfile=`echo $oldname | tr A-Z a-z`
0016     newfile=`echo $newname | tr A-Z a-z`
0017 fi
0018 
0019 if [ ! -f $newfile.h ]; then
0020     echo "Copying $oldfile.{cpp,h} to $newfile.{cpp,h}"
0021     cp $oldfile.h $newfile.h
0022     cp $oldfile.cpp $newfile.cpp
0023     if [ -f ${oldfile}_p.h ]; then
0024         cp ${oldfile}_p.h ${newfile}_p.h
0025     fi
0026     if [ -f ${oldfile}.ui ]; then
0027         echo "Copying $oldfile.ui to $newfile.ui"
0028         cp ${oldfile}.ui ${newfile}.ui
0029     fi
0030 
0031     git add $newfile.h
0032     git add $newfile.cpp
0033     if [ -f ${newfile}_p.h ]; then
0034         git add ${newfile}_p.h
0035     fi
0036     if [ -f ${newfile}.ui ]; then
0037         git add ${newfile}.ui
0038     fi
0039 fi
0040 
0041 # Update build system
0042 if test -f CMakeLists.txt; then
0043     buildsystemfile=CMakeLists.txt
0044     separator=
0045 else
0046     buildsystemfile=`ls -1 *.pro 2>/dev/null | head -n 1`
0047     separator=' \\'
0048 fi
0049 if test -n "$buildsystemfile"; then
0050     perl -pi -e '$_ .= "$1'$newfile.cpp"$separator"'\n" if (m/^(\s*)'$oldfile'\.cpp/)' $buildsystemfile
0051     perl -pi -e '$_ .= "$1'$newfile.h"$separator"'\n" if (m/^(\s*)'$oldfile'\.h/)' $buildsystemfile
0052     perl -pi -e '$_ .= "$1'$newfile.ui"$separator"'\n" if (m/^(\s*)'$oldfile'\.ui/)' $buildsystemfile
0053 fi
0054 
0055 # Rename class
0056 perl -pi -e "s/$oldname/$newname/g" $newfile.h $newfile.cpp
0057 if [ -f ${newfile}_p.h ]; then
0058     perl -pi -e "s/$oldname/$newname/g" ${newfile}_p.h
0059 fi
0060 if [ -f ${newfile}.ui ]; then
0061     perl -pi -e "s/$oldname/$newname/g" ${newfile}.ui
0062 fi
0063 
0064 oldinclguard=`echo $oldname | tr a-z A-Z`
0065 newinclguard=`echo $newname | tr a-z A-Z`
0066 
0067 # Update include guard
0068 perl -pi -e "s/$oldinclguard/$newinclguard/g" $newfile.h
0069 
0070 # Update includes in cpp file
0071 perl -pi -e 's/\b'$oldfile'\.h/'$newfile'\.h/' $newfile.cpp
0072 perl -pi -e 's/\b'$oldfile'\.moc/'$newfile'\.moc/' $newfile.cpp
0073